question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`##vso[task.setvariable]` does not work as expected if `issecret=true`

See original GitHub issue

According to https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md, I should be able to call Write-Host ("##vso[task.setvariable variable=testvar;issecret=true;]testvalue") in a Powershell build step and then call Write-Host "testvar: $Env:testvar" in a subsequent Powershell build step, but it doesn’t seem like the variable was saved because the output is just testvar: when I was expecting testvar: ********.

If I remove issecret=true;, it works as expected, but the value is not masked in the output.

Thank you.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ericsciplecommented, Jun 12, 2018

You need to use macro syntax in the input text boxes for secrets. Here is an example:

steps:
- powershell: |
    write-host '##vso[task.setvariable variable=myVariable]asdf'
    write-host '##vso[task.setvariable variable=mySecret;issecret=true]qwerty'
- powershell: |
    write-host "this works: $(myVariable)"
    write-host "this works: $env:MYVARIABLE"
    write-host "this works: $(mySecret)"
    write-host "this does not work: $env:MYSECRET"
1reaction
jtourlamaincommented, May 1, 2020

@jnoyola I use a powershell script that generates random characters (based on https://devblogs.microsoft.com/scripting/generate-random-letters-with-powershell/) At the end of the script I inject it into the pipeline via

Write-Host ("##vso[task.setvariable variable=$outputVariableName;issecret=true;]$randomPass")

The issecret means it doesn’t show up in logs. So, I don’t actually convert the random string to a secure string via the ConvertTo-SecureString but thanks to the issecret flag it stays hidden from logging.

In your ARM template, define your parameter as securestring like I mentioned above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

`##vso[task.setvariable]` does not work as expected if `issecret ...
Secret variables must be passed into tasks via inputs (i.e. text box). I'll clarify in the docs.
Read more >
vso[task.setvariable does not pass the variable onto the next ...
I have a process variable setup in my VSTS build called currentDate. I then have a PowerShell script that sets that variable to...
Read more >
Azure pipeline output variables task.setvariable is not ...
But I see that output variables using bash or script is not working in azure pipeline yml. I am using ubuntu agent. -...
Read more >
Classic release and artifacts variables - Azure Pipelines
setvariable logging command. Note that the updated variable value is scoped to the job being executed, and does not flow across jobs or...
Read more >
Gotchas when sharing variables with Azure DevOps stages ...
bash: echo "##vso[task.setvariable variable=secretValue3 ... immediately notice that our first var1 variable has been resolved as expected, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found