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

2

7

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.

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
Hammurabi answered 13/6, 2020 at 11:58 Comment(0)
R
8

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.

Radices answered 14/6, 2020 at 10:59 Comment(4)
Thanks @shayki, I am using the deployment job so I will exclude the download step.Hammurabi
So if we use deployment job, published artifacts are downloaded automatically?Chesson
@Chesson see here: learn.microsoft.com/en-us/azure/devops/pipelines/process/…Radices
FYI - if you use a deployment job & the auto download, they will be downloaded to the $(Pipeline.Workspace) path NOT $(System.ArtifactsDirectory) which confused me for a while. See: developercommunity.visualstudio.com/t/…Winer
T
4

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

Tetchy answered 15/6, 2020 at 7:28 Comment(2)
Great, thanks for the confirmation. I am using the deployment job, so I will exclude the download step.Hammurabi
Actually the artifacts aren't prefixed with the stage name when they are auto-downloaded in the deployment job. At least not for me 🤔Lizzettelizzie

© 2022 - 2024 — McMap. All rights reserved.