1
votes

I am trying to customize the output of my pipeline release through setting some env variables into a task. I found the following link: https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=powershell

which however does not seem to work. What I am doing is simply to create a pipeline with a single task (either bash or PS), and there declaring the commands specified in the link through the inline version of the task.

Has anyone already successfully managed to make these commands work? Do I do something wrong and/or incomplete?

Does anyone have a better way to customise the pipeline with relevant information from a task? E.g. through the release name, or the description and/or tag of the specific release?

Edit:

Write-Host "##vso[task.setvariable variable=sauce;]crushed tomatoes"
Write-Host "##vso[task.setvariable variable=secretSauce;issecret=true]crushed tomatoes with garlic"

Write-Host "Non-secrets automatically mapped in, sauce is $env:SAUCE"
Write-Host "Secrets are not automatically mapped in, secretSauce is $env:SECRETSAUCE"
Write-Host "You can use macro replacement to get secrets, and they'll be masked in the log: $(secretSauce)"

this is the code, copy and pasted. Now I tried also with the script, and it does not work either. I use an hosted windows agent.

1
I've used them before and they work, you just have to be correct with the syntax. For example the ; in the syntax is very important. What, exactly, you are executing?ta.speot.is
Make sure you're doing it as specified in the documentation, Write-Host "##vso[task.setvariable variable=testvar;]testvalue" not Write-Host "##vso[task.setvariable testvar=testvalue;]"ta.speot.is
Can you share your bash/PS scriptShayki Abramczyk
I just did copy and paste what's written in the documentation. Just to be clear, I do write everything directly inline, without uploading any bash/PS script. If you were successful with a script then this can be the key differenceNeo
@ShaykiAbramczyk I inserted the code. Please tell me if you have any other hint.Neo

1 Answers

4
votes

When you set a new variable with the logging command the variable is available only in the next tasks and not in the same task.

So, split your script to 2 tasks, in the second task put the last 3 lines and you will see that the first task works:

enter image description here