0
votes

I have create a YAML pipeline for Azure deployment. There are many templates, but I will only show the master pipeline to illustrate my issue.

Basically

  1. the first stage is to build from repository source.
  2. the next stage is pre-deployment followed by deployment

The build drops the output files to a drop folder. During pre-deployment some of these files go through some transformations (replacing tokens with values according to target environment).

The problem is that currently there is only one drop folder, so you can see the problem coming .... If I deploy to DEV, the files are transformed using the DEV values. But then if I deploy to INT, the files are already transformed and I end up deploying to INT files with DEV values.

It get worse if DEV and INT deployment run at the same time...

So how can I use separate drop folder per environment ? In predeployment, should I copy the drop folder to another location before transformation. In which case, how do I specify the new location in the deployment stages ?

Here's the master pipeline for reference :

trigger:
- master

pool:
  name: Default
  demands:
  - npm
  - msbuild
  - visualstudio

stages:

  - stage: build
    displayName: 'Build & Test stage'
    jobs: 
    - template: templates/pipeline-build/master.yml
      parameters:
        buildConfiguration: 'Release'
        dropFolder: '\\srvbuild\DROP'


  - stage: deployDev
    displayName: 'Deploy Dev Stage'
    dependsOn: build
    condition: succeeded()
    jobs:
    - deployment: deploymentjob
      displayName: deployment job
      environment: dev  
      variables:         
        - template: variables/dev.yml
      strategy:
        runOnce:
          preDeploy:
            steps:             
            - template: templates/pipeline-predeploy/master.yml
          deploy:
            steps:
            - template: templates/pipeline-deploy/master.yml 

  - stage: deployInt
    displayName: 'Deploy Int Stage'
    dependsOn: build
    condition: succeeded()
    jobs:
    - deployment: deploymentjob
      displayName: deployment job
      environment: int  
      variables:         
        - template: variables/int.yml
      strategy:
        runOnce:
          preDeploy:
            steps:             
            - template: templates/pipeline-predeploy/master.yml
          deploy:
            steps:
            - template: templates/pipeline-deploy/master.yml 
1

1 Answers

2
votes

As workaround, you can publish the build artifact to A file share, and then download the build artifact through the Download Fileshare Artifacts task in each stage to transform it separately.

- task: PublishPipelineArtifact@1
  displayName: 'Publish Pipeline Artifact'
  inputs:
    artifact: drop
    publishLocation: filepath
    fileSharePath: '***'

Use this task to download fileshare artifacts:

- task: DownloadFileshareArtifacts@1
  inputs:
    filesharePath: 
    artifactName: 
    #itemPattern: '**' # Optional
    #downloadPath: '$(System.ArtifactsDirectory)' 
    #parallelizationLimit: '8' # Optional