How to add secret variable as task environment variable in VSTS

丶灬走出姿态 提交于 2019-11-27 07:44:52

问题


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.


回答1:


Set Environment Variable

Use a Command Line task, like this:



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):




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




回答2:


When using the YAML-syntax this can be achieved too:

steps:
- script: |
    echo %MYSECRET%
  env:
    MySecret: ${Secret_Variable}



回答3:


You can supply variables to pass to tasks in the Variables page of the build definition:

Then they can be passed in to a task as an input like so:



来源:https://stackoverflow.com/questions/44037493/how-to-add-secret-variable-as-task-environment-variable-in-vsts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!