azure-devopsazure-pipelines

Download and publish artifact only if exist in azure pipeline


Using task of azure pipeline is it possible to download and publish artifact only if exists?

-> My first task is a build - but that build is a bit special, it will check if there is something that have changed since the last commit. If nothing has changed, nothing will be build.

-> The second task is the download artifact, but in the case nothing was build, there will be nothing to download.

Because no folder has been created by the build, my CI failed.

Is there a way to "tell" the download task: "download only if exist". Or continue to task 3 only if folder created otherwise finish.

Thank you


Solution

  • You can use for this purpose variables and set them dynamically based on the fact if you are going to create your artifact or not

      steps:
      - bash: |
          echo "Test here if you have folder which will you use to create an artifact and then set Yes or No"
          echo "##vso[task.setvariable variable=doThing]Yes" #set variable doThing to Yes
        name: DetermineResult
      - script: echo "Job Foo ran and doThing is Yes."
        condition: eq(variables['doThing'], 'Yes')
      - script: echo "Skip this one"
        condition: ne(variables['doThing'], 'Yes')