Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.gitlab-ci.yml.bck
node_modules/*
imgs/.DS_Store
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Cli Version Check:
script:
- npm i
- node ./cancelOldPipeline.js
- node ./utility/updateCommitStatus.js
- |
# Define installation directory and version file path
export CLI_FOLDER="$(pwd)/veracode-cli"
Expand Down Expand Up @@ -218,4 +219,4 @@ workflow:
PIPELINE_NAME: "${PROJECT_NAME} - SCA Scan"
- if: '$EXECUTE_IAC == "true"'
variables:
PIPELINE_NAME: "${PROJECT_NAME} - IAC Scan"
PIPELINE_NAME: "${PROJECT_NAME} - IAC Scan"
28 changes: 26 additions & 2 deletions cancelOldPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,43 @@ async function cancelOldPipeline() {
return;
}

// Find the current pipeline in the list to get its full timestamp with milliseconds
const currentPipeline = pipelines.find(p => p.id === Number(currentPipelineId));
const currentPipelineCreatedAtFull = currentPipeline ? currentPipeline.created_at : currentPipelineCreatedAt;

console.log('#### DEBUG - Current Pipeline Info ####');
console.log('currentPipelineId:', currentPipelineId);
console.log('currentPipelineCreatedAt (env):', currentPipelineCreatedAt);
console.log('currentPipelineCreatedAt (from API):', currentPipelineCreatedAtFull);
console.log('#### DEBUG - Current Pipeline Info ####');

for (const pipeline of pipelines) {
const pipelineId = pipeline.id;

console.log('#### DEBUG - Cancel Old Pipeline ####');
console.log('pipelineId:', pipelineId);
console.log('currentPipelineId:', currentPipelineId);
console.log('pipeline.created_at:', pipeline.created_at);
console.log('#### DEBUG - Cancel Old Pipeline ####');

// Skip current pipeline itself
if (pipelineId === Number(currentPipelineId)) {
console.log(`Skipping current pipeline ${pipelineId}`);
continue;
}

// Convert current pipeline creation time to epoch milliseconds
const currentEpoch = new Date(currentPipelineCreatedAt).getTime();
// Convert pipeline creation times to epoch milliseconds
// Use the full timestamp from API for accurate comparison
const currentEpoch = new Date(currentPipelineCreatedAtFull).getTime();
const createdEpoch = new Date(pipeline.created_at).getTime();

console.log('#### DEBUG - Time Comparison ####');
console.log('currentEpoch:', currentEpoch);
console.log('createdEpoch:', createdEpoch);
console.log('Difference (ms):', createdEpoch - currentEpoch);
console.log('Is createdEpoch > currentEpoch?', createdEpoch > currentEpoch);
console.log('#### DEBUG - Time Comparison ####');

// Skip newer pipelines
if (createdEpoch > currentEpoch) {
console.log(`Skipping newer pipeline ${pipelineId} created at ${pipeline.created_at}`);
Expand Down
11 changes: 6 additions & 5 deletions displayScanResult.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { createWikiPage, createComment } = require('./utility/service');
const { scaResult, pipelineResult, policyResult, iacResult } = require('./utility/utils');
const { appConfig } = require('./config');
async function displayScanResult(scanResult, warningMessage = "") {
async function displayScanResult(scanResult, warningMessage = "", debug = null) {
const executePipeline = process.env.EXECUTE_PIPELINE;
const executeSca = process.env.EXECUTE_SCA;
const executeIac = process.env.EXECUTE_IAC;
Expand All @@ -13,17 +13,18 @@ async function displayScanResult(scanResult, warningMessage = "") {
if (eventName === appConfig().pullRequestEventName || eventName === appConfig().pushEventName) {
try {
if ((scanType === "IaC" && Object.entries(scanResult).length > 0) || scanResult.length > 0) {
let formattedContent = scanType === 'SCA' ? scaResult(scanResult[0]) : scanType === 'Pipeline' ? pipelineResult(scanResult) : scanType === 'IaC' ? iacResult(scanResult) : policyResult(scanResult);
const sourceBranch = process.env.SOURCE_BRANCH;
let formattedContent = scanType === 'SCA' ? scaResult(scanResult[0]) : scanType === 'Pipeline' ? await pipelineResult(scanResult, sourceBranch, projectUrl, debug) : scanType === 'IaC' ? iacResult(scanResult) : policyResult(scanResult);
const wikiContent = `${scanType} Scan completed. :white_check_mark:\n\n` + formattedContent;
const createWikiResponse = await createWikiPage(scanType, projectUrl, wikiContent);
const commentContent = createWikiResponse.hasOwnProperty('wikiUrl') && createWikiResponse?.wikiUrl !== "" ? `<a href=${createWikiResponse.wikiUrl} target="_blank">${scanType} Scan completed.</a> :white_check_mark:\n\n` + formattedContent : `${scanType} Scan completed. :white_check_mark:\n\n` + formattedContent;
const commentContent = createWikiResponse.hasOwnProperty('wikiUrl') && createWikiResponse?.wikiUrl !== "" ? `<a href=${createWikiResponse.wikiUrl} target="_blank">${scanType} Scan completed.</a>\n\n` + formattedContent : `${scanType} Scan completed.\n\n` + formattedContent;
await createComment(projectUrl, mergeRequestId, eventName, commitSha, commentContent);
} else {
let commentContent = "";
if (warningMessage) {
commentContent = `${scanType} Scan completed. :warning:\n\n` + `${warningMessage}\n`;
commentContent = `${scanType} Scan completed.\n\n` + `${warningMessage}\n`;
} else {
commentContent = `${scanType} Scan completed. :white_check_mark:\n\n` + 'No Vulnerability found.\n';
commentContent = `${scanType} Scan completed.\n\n` + 'No Vulnerability found.\n';
}
await createComment(projectUrl, mergeRequestId, eventName, commitSha, commentContent);

Expand Down
Binary file added imgs/High.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/Informational.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/Low.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/Medium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/Very_High.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/Very_Low.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading