Is it possible to set an VSTS Build variable in a

2019-03-17 23:29发布

I'm currently using Build in Visual Studio Team Services (was Visual Studio Online), and would like to be able to set a Build Variable in a Build Step so that the new value can be used in a subsequent Build Step.

Obviously you can set it before the Build starts but I'm looking to late bind the variable during a subsequent Build Step.

Is this possible?enter image description here

3条回答
Animai°情兽
2楼-- · 2019-03-17 23:48

When inside of a script you can update a variable by emitting the following in your ps1

"##vso[task.setvariable variable=testvar;]testvalue"

You can then pass the variable into the next script using $(testvar)

查看更多
Animai°情兽
3楼-- · 2019-03-18 00:05

This doc from the API talks about what ##vso commands you can use.

Don't forget to set system.debug to true. It seems there is a bug that muted stdout and thus, all ##vso are not working.

https://github.com/Microsoft/vso-agent-tasks/blob/master/docs/authoring/commands.md

查看更多
来,给爷笑一个
4楼-- · 2019-03-18 00:09

You can create a powershell script an reference it as a build task. Then inside your powershell scripts add this:

"##vso[task.setvariable variable=key]value"

After that on all your tasks you can read the variable as $(key). If you want to protect your variable, use:

"##vso[task.setvariable variable=secretVar;issecret=true]value"

And then use it as $(secretVar) in your next tasks.

查看更多
登录 后发表回答