I’m working on an Azure DevOps pipeline where I need to pass environment variables to a job template. Instead of passing these environment variables as a single string, I want to pass them as an object for better manageability.
As a string (current approach – works but it’s hacky):
parameters:
- name: envVars
type: string
default: ""
...
- script |
${{ parameters.envVars}} <rest of command>
...
As an object:
parameters:
- name: envVars
type: object
default: { ENV_VAR: "value_example" }
- script |
<rest of command>
env:
${{ parameters.envVars }}
In the second case, I would hope that Azure DevOps unwraps the envVars object properly and would be equivalent to having
env:
ENV_VAR: "value_example"
ENV_VAR_B: "other_value"
...
# can still have other environment variables here that are not present in envVars
However, I’m not finding any proper documentation from Azure DevOps around this and not exactly sure what would be the best way to unwrap the envVars object and pass it to the script. Any guidance or improvements on this setup would be greatly appreciated!