Search code examples
azureazure-devopsazure-pipelinesazure-pipelines-build-taskazure-pipelines-tasks

How to set or inject an arbitrary file list of environment variables in an Azure Pipeline


I'm porting some Jenkins builds to Azure Pipelines. One of the port sets involves an arbitrary list of environment variables that constantly changes. In Jenkins I just run an injection script to run on a list file that is within the code base's source and the build references those variables in whatever scripts or build-steps need them. Some of the variables are hard-coded while others reference environment variables of the build itself.

I looked at the Define variables documentation but it either doesn't show a way to accomplish this, or I somehow missed it. How do I go about doing this besides resorting to something like Setx ? I have no way of knowing which build will use which variables so hard-coding them is pointless. The only constant is, I know to look for a root-level file called env-vars.txt.


Solution

  • There is an Azure Pipelines build Task module available on the VS Marketplace that can do this called Json to Variable, by Jeff Przylucki. I can either request the repo's devs to update their env-vars.txt into a JSON or run an existing tool to convert Key=Value pairs to JSONs.

    Task that will read a JSON file present on your build agent, from a build or a release, and will Generate Build/Release Variables to be used in other steps.

    Json to Variable: https://marketplace.visualstudio.com/items?itemName=OneLuckiDev.json2variable