Raju Rh
Raju Rh

Reputation: 147

Multi-Stage Release pipeline variable value overriden by current value during rerun

In the classic release pipeline when you rerun a release build the same variables that were used when the release was initially created were used. In multi stage pipeline I am seeing the value is picked freshly/newly when even when we rerun the existing deployed stage.

Expected: Use the same variable which was used in the initial run rather than using the new one.

The variable which I am referring being overridden is read from Keyvault which is kept in the Azure DevOps variable group.

https://github.com/MicrosoftDocs/azure-devops-docs/issues/7663

Upvotes: 0

Views: 1616

Answers (2)

kuytsce
kuytsce

Reputation: 103

I know this is an old question, but as I found myself here looking for a solution to this issue I thought I'd add an answer/work around for anyone else who may require it.

As already answered, with yaml pipelines, the library variables will always retrieve the current variable value from the variable group even if re-running an old completed pipeline.

As a work around solution I have done the following:

  • Previously in my pipeline, in a single stage I would replace tokens in our yaml files with variables from our variable group and then immediately apply the yaml files in Kubernetes.
  • I removed the replace tokens step from that stage of the pipeline and put it into its own stage, earlier in the pipeline.
  • Inside my replace token stage, after the tokens are replaced I publish each yaml file into my artifact staging directory, example code below:
    - publish: '$(Build.ArtifactStagingDirectory)/deployment.yaml'
      artifact: 'deployment'
      displayName: 'Publishing the deployment yaml file'
  • Back to the stage of my pipeline where the yaml files are applied. I first download the published yaml files as per the code below:
    - task: DownloadPipelineArtifact@2
      inputs:
        artifactName: 'deployment'
        targetPath: $(Build.ArtifactStagingDirectory)/bin
  • When applying the yaml files, I now point the command to the downloaded artifact versions e.g. $(Build.ArtifactStagingDirectory)/bin/deployment.yaml

The downloaded versions of the yaml files still contain the variable values from when the file was first published. Therefore if you need to re-run an old pipeline, the old variable values will be used. The published yaml files exist for as long as the record of your pipeline exists in Azure DevOps.

Upvotes: 0

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31083

Any changes made centrally to a variable group, such as a change in the value of a variable or the addition of new variables, will automatically be made available to all the definitions or stages to which the variable group is linked. In YAML pipeline, to use a variable from a variable group, you need to add a reference to the group in your YAML file:

variables:
- group: my-variable-group

So each time you run or rerun a YAML pipeline, it will get the variables from the variable group. If there is any changes made to variable group, the pipeline will get the new changes.

While in the classic release pipeline, the variables won't change in the variable group linked to an existing release, so when you redeploy the pipeline or stages, you can still use the original variables.

enter image description here

It's the default behavior of classic release pipeline and YAML pipeline, we can not change it.

Upvotes: 2

Related Questions