1

I have an Azure Pipeline, that consumes the artifacts produced by another pipeline. Something like this

resources:
  pipelines:
  - pipeline: BuildPipeline
    source: project-ci

With this reference, I can reference some pipeline resource variables like resources.pipeline.BuildPipeline.runName.

The question is, other than the predefined variables (list here), is it possible to publish a custom variable in the first pipeline so it's available later as a resource variable?

lastr2d2
  • 3,604
  • 2
  • 22
  • 37
  • Between pipelines? No. What data are you trying to persist? – Daniel Mann Aug 08 '21 at 22:12
  • it's a string that represents a version number of part of my artifacts. somehow I can't version this part of the artifact with the build number hence this ask – lastr2d2 Aug 08 '21 at 22:16
  • 1
    Two parts. Yes you can publish a file containing set of variables to be carried over to secondary pipeline. In the secondary, download artifact task and read them in a task as an intermediary. – koushik Aug 09 '21 at 06:23
  • the artifact file is an overkill for me. as a quick fix, I ended up with a pipeline parameter that can be manually overwritten by user input. I will leave this question open just in case there is an out of box solution – lastr2d2 Aug 09 '21 at 07:24

1 Answers1

1

The question is, other than the predefined variables (list here), is it possible to publish a custom variable in the first pipeline so it's available later as a resource variable?

I am afraid there is no such directly way to publish a custom variable in the first pipeline as a resource variable at this moment.

As workaround, we could use the REST API in the rescource pipeline to update the variable in the Variables tab for the current pipeline.

Steps:

  • Define a variable in the later pipeline definition Variable.

  • Add a task to invoke REST API (Definitions - Update) in rescource pipeline to update the value of the above variable in the later release pipeline.

  • Use the updated value of the later pipeline variable in the later pipeline.

The details info about using REST API to update the value of the definition variable, you can follow the below ticket:

How to modify Azure DevOps release definition variable from a release task?

or you could use the Azure CLI to update the variable:

az pipelines variable update --name
                             [--allow-override {false, true}]
                             [--detect {false, true}]
                             [--new-name]
                             [--org]
                             [--pipeline-id]
                             [--pipeline-name]
                             [--project]
                             [--prompt-value {false, true}]
                             [--secret {false, true}]
                             [--subscription]
                             [--value]
Leo Liu
  • 71,098
  • 10
  • 114
  • 135