How do I update a pipeline variable in an azure task?

I'm currently thinking og using the Azure cli to do this:
- Login to az
- use az
pipelines variable update --name=AppVersion --value=7.13.1command to update
I also tried updating the variable without the AZ CLI but could not get the $AppVersion to update properly. Is it possible to update the $AppVersion in a task without the AZ CLI?
I tried a powershell script:
Write-Host $(AppVersion) # 18.13.0
$AppVersion = "9.0.0"
##vso[task.setvariable variable=AppVersion;isOutput=true]9.0.0
$env:AppVersion = '9.0.0'
Write-Host $(AppVersion) # Still 18.13.0
To use powershell to create/update an Azure DevOps variable, the syntax will look as follows:
or
Two things to note when updating a variable in this way:
AppVersionvariable for the current job. Subsequent jobs will not be aware of the variable update. This can be achieved by using;IsOutput=true, and redefining the variable within that job or stage.Taking the above notes into account, here is the values of AppVersion in an example yaml:
Depending on how you determine if
AppVersionshould be updated or not, you can achieve a global update ofAppVersionby updating it underneathvariables:in your yaml file: