Skip to content

Commit

Permalink
Add jsonOutputPath option
Browse files Browse the repository at this point in the history
  • Loading branch information
georg-jung committed Oct 15, 2024
1 parent 327177f commit ab04703
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions marketplace.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You can supply several inputs to customise the task.
| `aquaSecret` | The Aqua API Secret to use to link scan results to your Aqua Security account _(not required)_. |
| `options` | Additional flags to pass to trivy. Example: `--timeout 10m0s` _(not required)_. |
| `additionalCommandsWithResult` | Additional trivy commands to execute, one per line, with the path to the result.json file appended. E.g. `convert --format cyclonedx --output result.cdx` |
| `jsonOutputPath` | A path to a file where trivy saves it's output. Defaults to a random temporary path. Can be overriden e.g. to upload the output as an artifact. E.g. `$(Build.ArtifactStagingDirectory)/trivy-code-scan-results.json` |

### Example of scanning multiple targets

Expand Down
7 changes: 4 additions & 3 deletions trivy-task/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ const latestTrivyVersion = "v0.56.2"
const tmpPath = "/tmp/"

async function run() {
let configuredJsonOutputPath = task.getInput("jsonOutputPath", false)

console.log("Preparing output location...")
const outputPath = tmpPath + "trivy-results-" + Math.random() + ".json";
const outputPath = configuredJsonOutputPath ?? (tmpPath + "trivy-results-" + Math.random() + ".json");
console.log("Preparing output location " + outputPath + "...")
task.rmRF(outputPath);

let scanPath = task.getInput("path", false)
Expand Down Expand Up @@ -43,7 +44,7 @@ async function run() {
process.env.AQUA_ASSURANCE_EXPORT = assurancePath
}

const runner = await createRunner(task.getBoolInput("docker", false), loginDockerConfig, false);
const runner = await createRunner(task.getBoolInput("docker", false), loginDockerConfig, configuredJsonOutputPath !== undefined);

if (task.getBoolInput("debug", false)) {
runner.arg("--debug")
Expand Down

0 comments on commit ab04703

Please sign in to comment.