Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add secret variable as task environment variable in VSTS

This documentation states that secret variables are

Not decrypted into environment variables. So scripts and programs run by your build steps are not given access by default.

One of my build tasks require that an environment variable be set that is stored in a secret variable. Does this mean it's impossible to do this using secret varaibles in VSTS? If not, how do I do this?

For further background, I'm trying to code sign my electron app using electron-builder. It requires that two environment variables be set: CSC_LINK and CSC_KEY_PASSWORD. One of these is the password to a code signing certificate so needs to be kept secure.

like image 720
ajbeaven Avatar asked May 18 '17 02:05

ajbeaven


People also ask

How do you pass variables between tasks in Azure Devops?

Share variables between Tasks across the Jobs (of the same Stage) We need to use the isOutput=true flag when you desire to use the variable in another Task located in another Job. Navigate to Stage1_Job1_Task1 and add isoutput = true flag to the Logging Command which let's us to access the value outside the Job.


1 Answers

Set Environment Variable

Use a Command Line task, like this:

VSTS Build - copy secret var to environment var

target_environment_variable now contains the value of secret_variable.

Verify

Add a subsequent Command Line task that writes all environment variables to a disk file, like this: (note: in the Arguments text box, write to a folder that both you and build agent can access):

VSTS Build - write env vars to disk


Queue the build definition, then view the file containing the environment variables:

VSTS Build - view file of env vars

like image 156
Richard II Avatar answered Oct 29 '22 13:10

Richard II