Search code examples
azure-devopsartifact

Azure Devops - Can not retrieve artifact


I am publishing a artifact in a job (which completes successfully). In a separate job, I am trying to retrieve the artifact. However, nothings shows in the ls $(Build.ArtifactStagingDirectory). Why is this?

      - task: PublishPipelineArtifact@1
        displayName: 'Publish Artifact'
        inputs:
          targetpath: 'anatomy/dist'
          artifact: 'anatomy-artifact'
          publishLocation: 'pipeline'

  - job: deployBucket
    displayName: 'Deploy Bucket'
    dependsOn: buildAnatomy
    condition: eq(dependencies.buildAnatomy.result,'Succeeded')
    pool:
      vmImage: "ubuntu-20.04"

    steps:

      - task: Bash@3
        displayName: "Upload contents to bucket"
        inputs:
          targetType: "inline"
          script: |
            ls -al '$(Build.ArtifactStagingDirectory)'

Solution

  • Each job runs in its own space and the agent cleans up after itself by default. If you want the contents of the artifact to be available in the 2nd job, you need to fetch it again.

    Use the DownloadPipelineArtifact@1 task at the start of your 2nd job.

    Or move the deploy command into the same job.