Search code examples
azure-devopsazure-pipelinestrivy

how to download trivy output within a pipeline


I have got a step within an Azure DevOps pipeline which scans a container using trivy.

The Azure powershell task as as follows.

trivy -v
$folder = Get-Location
$filename = "report-$(Build.BuildId)-$(Build.DefinitionName).json"
trivy image -f json -o $filename python:3.4-alpine
$fullfile = Join-Path $folder $filename
write-host $fullfile
echo "Structure of work folder of this pipeline:"
tree $(Agent.WorkFolder) /f

echo "Build.ArtifactStagingDirectory:" 

echo "$(Build.ArtifactStagingDirectory)"

echo "Build.BinariesDirectory:" 

echo "$(Build.BinariesDirectory)"

echo "Build.SourcesDirectory:"

echo "$(Build.SourcesDirectory)"

The file generated is as follows.

/home/vsts/work/1/s/report-6949-my-test-pipeline.json

I would like to be able to download the file from the pipeline as an artifact or perhaps upload it onto a storage account.


Solution

  • Just add a publish artifacts step that publish the .json file:

      - task: PublishPipelineArtifact@1
        inputs:
          targetPath: '$(Build.SourcesDirectory)/report-$(Build.BuildId)-$(Build.DefinitionName).json'
          artifact: 'trivy-output'
          publishLocation: 'pipeline'
    

    Result:

    enter image description here