4

I am trying to overwrite the value of the variable from Variable Group in Azure DevOps and it's not working. It's always showing the original value.

I wrote my Powershell scripts as shown by these links:

I added the Variable Group and Link it in my Build pipeline.

enter image description here

I wrote the following scripts in Power Shell Script task.

Write-Host "Original BPOwner = $(BPOwner)"

Write-Host "Changing value of BPOwner to Bright Ran"
Write-Host "##vso[task.setvariable variable=BPOwner;]Bright Ran"

Write-Host "New BPOwner = $(BPOwner)"

However, in the Build, it's always showing the original value and it's never changed to the value I want to set.

enter image description here

Could you please suggest me how I could set this value in the Build Pipeline?

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
TTCG
  • 8,805
  • 31
  • 93
  • 141

1 Answers1

4

The new value available only in the next tasks, not in the same task when you change the value. for example, I added another PS task with Write-Host "New BPOwner = $(BPOwner)":

enter image description here

The above it's the behavior of the logging command ##vso[task.setvariable variable] and not only to the variable group.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • Yes, if I add another Task and write the new value, it works as expected. Actually, I am trying to set the value in Build Pipeline and re-use it in Release in AzureDevOps. In Release task, it's always set to original value and never updated. Could you pls help? – TTCG Aug 27 '19 at 12:59
  • Do you want to change the value in the build and in the release get the new value? – Shayki Abramczyk Aug 27 '19 at 13:02
  • yes, correct. I want to get that dynamic value and re-use that new value in Release – TTCG Aug 27 '19 at 13:17
  • @TTCG you can do it with rest API, see my answer: https://stackoverflow.com/questions/56558143/is-there-a-way-to-set-variables-in-variable-groups/56558502#56558502 – Shayki Abramczyk Aug 27 '19 at 13:19