Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Variables in Azure Pipeline Task Failing

I have a simple powershell task in my pipeline definition to grab the date information and set some build variables

[string]$buildNum=$(Build.BuildNumber);

$year=$(Get-Date -Format yyyy);
$month=$(Get-Date -Format MM);
$day=$(Get-Date -Format dd);
$revnum= $buildNum.Substring($buildNum.LastIndexOf('.') + 1);

Write-Host "##vso[task.setvariable variable=major]$year$month"
Write-Host "##vso[task.setvariable variable=minor]$day"
Write-Host "##vso[task.setvariable variable=patch]$revnum"

The task keeps failing with:

##[error]Unable to process command '##vso[task.setvariable variable=major;]201910' successfully. Please reference documentation (http://go.microsoft.com/fwlink/?LinkId=817296)

[error]##vso[task.setvariable variable=major;] is not a recognized command for Task command extension. Please reference documentation (http://go.microsoft.com/fwlink/?LinkId=817296)

I have seen the syntax as both:

Write-Host "##vso[task.setvariable variable=major]$year$month"

and

Write-Host "##vso[task.setvariable variable=major;]$year$month"

both result in the same error.

enter image description here enter image description here

Build definition enter image description here enter image description here

Variables enter image description here

like image 582
JDBennett Avatar asked Oct 24 '25 03:10

JDBennett


1 Answers

Thanks to YanSklyarenko!

It looks like a copy and paste was bringing in an unseen character.

I manually re-typed it out and got it to work.

like image 61
JDBennett Avatar answered Oct 26 '25 18:10

JDBennett