I have the Variable Group defined in the Library:
I'm trying to override the value of the variable defined in above library in the specific task of Azure DevOps YAML Pipeline:
trigger:
- none
pool:
vmImage: ubuntu-latest
variables:
- group: DevGroup
steps:
- script: |
echo "##vso[task.setvariable variable=VanisJob;isoutput=true]FSDeveloper"
echo $(VanisJob)
- script: |
echo $(VanisJob) is the 2nd Job
Result:
1st Script result
2nd script result - here value should be changed as defined in the YAML Pipeline but not changed
From your yaml sample, you are using logging command to set the variable name: HarisJob.
The variable name is different from the variable name in the Variable group.
In this case, it will create a new variable(name: HarisJob) instead of overriding the variable value in the Variable Group.
To solve this issue, you need to set the same variable name in the Pipeline and the variable group when using logging command to set the variable.
For example:
pool:
vmImage: ubuntu-latest
variables:
- group: DevGroup
steps:
- script: |
echo "##vso[task.setvariable variable=VanisJob]FSDeveloper"
echo "$(VanisJob)"
- script: |
echo "$(VanisJob) is the 2nd Job"
Result:
Note: You need to remove the isoutput=true in the logging command, otherwise the variable name will change to $(CMDLINE1.VANISJOB)
For example:
echo "##vso[task.setvariable variable=VanisJob]FSDeveloper"