2
votes

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

1
I tried it and is working, which agent do you use? can you test another variable name, another value?Shayki Abramczyk
@ShaykiAbramczyk - I have tried both with Hosted 2017 and Azure Pipelines vs2017-win2016. What is driving me crazy is this same task works in a different build definition on a Hosted 2017 agent.JDBennett
this wouldn't be a direct answer to your question,but i think what you are doing can be solved with gitversion in a much better fashion, or just straight out azure devops build naming conventions4c74356b41
@JDBennett I wonder if that could be a different symbol in the command name, which looks like the normal English letter, but in fact, has a different code. It often happens with quotes, when you copy the text from somewhere, but might be the case with other characters... Can you try to literally re-type the command - everything inside the Write-Host "......"?Yan Sklyarenko
@YanSklyarenko - Man alive you found it! That did it.JDBennett

1 Answers

1
votes

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.