Skip to content

Commit 6436b68

Browse files
owenrumneyCopilot
andauthored
fix: need a default threshold for failure threshold (#186)
Co-authored-by: Copilot <[email protected]>
1 parent ef86484 commit 6436b68

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

trivy-task/trivyV1/task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"author": "Aqua Security",
1111
"version": {
1212
"Major": 1,
13-
"Minor": 18,
14-
"Patch": 2
13+
"Minor": 19,
14+
"Patch": 1
1515
},
1616
"instanceNameFormat": "Echo trivy $(version)",
1717
"groups": [

trivy-task/trivyV2/index.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ function highestSeverityBreached(
9393
inputs: TaskInputs,
9494
resultsFilePath: string
9595
): boolean {
96-
if (!inputs.failOnSeverityThreshold) {
97-
return false;
98-
}
9996
task.debug(`Fail on severity threshold: ${inputs.failOnSeverityThreshold}`);
10097

10198
const severityThreshold = inputs.failOnSeverityThreshold.toUpperCase();
@@ -132,18 +129,30 @@ function checkScanResult(exitCode: number, inputs: TaskInputs) {
132129
);
133130

134131
task.debug(`Highest severity breached: ${isHighestSeverityBreached}`);
135-
if (exitCode === 2 && inputs.ignoreScanErrors && isHighestSeverityBreached) {
136-
task.setResult(task.TaskResult.SucceededWithIssues, 'Issues found.');
137-
} else if (
138-
exitCode === 2 &&
139-
!inputs.ignoreScanErrors &&
140-
isHighestSeverityBreached
141-
) {
142-
task.setResult(task.TaskResult.Failed, 'Issues found.');
143-
} else if (exitCode === 2 && !highestSeverityBreached) {
144-
task.setResult(task.TaskResult.Succeeded, 'No issues found.');
132+
if (exitCode === 2 && inputs.ignoreScanErrors) {
133+
if (isHighestSeverityBreached) {
134+
task.setResult(task.TaskResult.SucceededWithIssues, 'Issues found.');
135+
return;
136+
} else {
137+
task.setResult(
138+
task.TaskResult.Succeeded,
139+
'Issues found but ignoring scan errors as per configuration.'
140+
);
141+
return;
142+
}
143+
} else if (exitCode === 2 && !inputs.ignoreScanErrors) {
144+
if (isHighestSeverityBreached) {
145+
task.setResult(task.TaskResult.Failed, 'Issues found.');
146+
} else {
147+
task.setResult(
148+
task.TaskResult.Succeeded,
149+
'No issues found.'
150+
);
151+
}
152+
return;
145153
} else {
146154
task.setResult(task.TaskResult.Failed, 'Trivy runner error.', true);
155+
return;
147156
}
148157
}
149158

trivy-task/trivyV2/inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function getTaskInputs(): TaskInputs {
4747
showSuppressed: task.getBoolInput('showSuppressed', false),
4848
ignoreScanErrors: task.getBoolInput('ignoreScanErrors', false),
4949
failOnSeverityThreshold:
50-
task.getInput('failOnSeverityThreshold', false) ?? '',
50+
task.getInput('failOnSeverityThreshold', false) ?? 'UNKNOWN', // default to UNKNOWN
5151
reports: task.getDelimitedInput('reports', ',').map((s) => s.trim()),
5252
publish: task.getBoolInput('publish', false),
5353
templates: task.getInput('templates', false),

trivy-task/trivyV2/task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"author": "Aqua Security",
1111
"version": {
1212
"Major": 2,
13-
"Minor": 5,
14-
"Patch": 2
13+
"Minor": 6,
14+
"Patch": 1
1515
},
1616
"instanceNameFormat": "Echo trivy $(version)",
1717
"groups": [

0 commit comments

Comments
 (0)