Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I have to explicitly download an artefact in an Azure DevOps pipeline?

I'm using Azure DevOps to create a pipeline that will have one stage to build and publish a Function App as an artefact, and then subsequent stages to deploy the Function App through the required life cycle.

What I'm unsure of is whether or not I need to explicitly download the artefact created by the build and publish stage in the subsequent deployment stages? There is plenty of documentation around this, but it's somewhat ambiguous and I can't see a mention of this particular issue.

  • YAML schema reference
  • Publish and download artifacts

    Artifacts are associated with the run they were produced in and remain available after the run has completed.

Here is an example of my pipeline. The Dev, Staging and Production stages incorporate a deployment strategy, and on many occasions there will be a delay (maybe days) between deployment of those stages.

stages:
- stage: Publish
  displayName: Publish Function App
  jobs:
  - ...
- stage: Dev
  displayName: Deploy Dev
  jobs:
  - ...
- stage: Staging
  displayName: Deploy Staging
  jobs:
  - ...
- stage: Production
  displayName: Deploy Production
  jobs:
  - ...

To publish the artefact containing my Function App I am using the publish step within the last job of the Publish stage.

- publish: $(System.DefaultWorkingDirectory)
  artifact: FunctionApp

My question is, do I need to use the corresponding download step in the Dev, Staging and Production deployment stages, or will the artefact always be available at $(Pipeline.Workspace)? Remember that I won't immediately progress through the deployment stages.

- download: current
  artifact: FunctionApp
like image 387
David Gard Avatar asked Jun 13 '20 11:06

David Gard


2 Answers

Yes, you need to add the download artifacts step in each stage, unless you specify the job is deployment job:

- stage: Dev
  displayName: Deploy Dev
  jobs:
  - deployment: Staging
    environment: 'Dev'
    strategy:
      runOnce:
        deploy:
          steps:
            - powershell: Write-Host "Test"

More info about the deployment job you can find here.

like image 98
Shayki Abramczyk Avatar answered Nov 15 '22 10:11

Shayki Abramczyk


If you use Microsoft-hosted agent. Every job defined in the yaml pipeline will run on a fresh new virtual machine. The virtual machine is discarded after one use.

So that the build artifacts from Build job of Build stage doesnot exist on the agent machine of the deploy job of Deploy stage. That's why you need to explicitly download the artifact built and published in the Publish stage in the subsequent deployment stages.

When you use download task, artifacts are downloaded to $(Pipeline.Workspace)/{artifact}, where artifact is the name of the artifact. The folder structure of the artifact is always preserved. See here.

If you use deployment job in the subsequent deployment stages as Shayki mentioned. Then you donot need to explicitly use download task. For Download artifact task will be auto injected only in the deploy hook for deployment jobs. See here.

The artifacts will be downloaded to folder $(Pipeline.Workspace)/{previousStageName.jobName} on the deployment job agent machine. See below screenshot from my test pipeline.

enter image description here

like image 38
Levi Lu-MSFT Avatar answered Nov 15 '22 11:11

Levi Lu-MSFT