Padmapriya Kp
Padmapriya Kp

Reputation: 55

How to get the value of secret variable provided in release pipeline

I have accidentally deleted a secret variable value in my release pipeline. same variable and value is configured in another release pipeline of same project.

I wanted to know is there any way through rest api I can get the secret variable value.

Upvotes: 0

Views: 6223

Answers (3)

coder555
coder555

Reputation: 33

In a method similar to Kevin Lu's mentioned above, but a bit simpler, you can:

  1. Add Powershell task (as first step?) in your release pipeline
  2. In the environment variables section of this task list the variables you need to get the value of, eg: Name: test1 Value: $(YourSecretVariableName)
  3. Add corresponding inline Powershell code: Write-Host $env:test1.ToCharArray()
  4. Throw exception to stop pipeline going further after your secret secrets have been revealed: throw "stop here"
  5. Remember not to leave this task in your pipeline.. :)

Upvotes: 1

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35574

I wanted to know is there any way through rest api I can get the secret variable value.

I am afraid that there is no such method can get the Secret Variable via Rest API.

Secret variables cannot be displayed directly in the pipeline.

But you can display specific values by outputting it to a file.

Here is an example: You can add PowerShell task to output the value to txt file, then you can use logging commnad to publish the file in Release Pipeline.

$env:test1 | Out-File $(System.DefaultWorkingDirectory)\debug.txt

Write-host "##vso[task.uploadfile]$(System.DefaultWorkingDirectory)\debug.txt"

enter image description here

Then you can download the txt file with the Release Logs. The value of the secret variable is in the txt file.

enter image description here

Upvotes: 3

Krzysztof Madej
Krzysztof Madej

Reputation: 40929

There is no way to fetch this secret. However if you have this in past releases you can modify your release

enter image description here

as it takes snapsot of your data. However, you should find a safe way of exposing this just to you. If you print it just to logs it will be masked. You may try to use azure cli te set variable in some variable group via this command


az pipelines variable-group variable update

[Here](Azure DevOps CLI in Azure Pipeline YAML) you have docs about running azure cli from yaml but it should be easy to move it to classic releases.

Upvotes: 0

Related Questions