How to access an artifact's BUILDNUMBER is Visual Studio Team Services Release management

↘锁芯ラ 提交于 2019-12-11 03:17:18

问题


I need to access the build number of the artifact within Visual Studio Team Services Release Management, so that I can send the value to a Task.

My artifact name has a space in it: "Production Branch"

I have been reading the following documentation.

https://www.visualstudio.com/en-us/docs/release/author-release-definition/understanding-artifacts#variables

The documentation states that it can be accessed like this:

RELEASE_ARTIFACTS_[source-alias]_[variable-name]

e.g.

RELEASE_ARTIFACTS_Production Branch_BUILDNUMBER

It goes on to say that if being used to pass an Argument to a task, replace the underscore with a period so:

RELEASE.ARTIFACTS.Production Branch.BUILDNUMBER

However this results in the following error:

2017-02-02T12:15:49.6988066Z ##[error]The term 'Release.Artifacts.Production_Branch.BUILDNUMBER' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

This could be due to the artifact name containing a space character and I am unsure of how to handle this.


回答1:


If you want to get it in PowerShell script, using this code instead:

$env:RELEASE_ARTIFACTS_[alias]_BUILDNUMBER

If you want to pass it as variable, using this code instead:

$(RELEASE.ARTIFACTS.[alias].BUILDNUMBER)

You can get detail variables in Download Artifacts step log:




回答2:


When you access the variable from PowerShell, you need to use "_" to replace the space in the name, for example:

Write-Host $env:RELEASE_ARTIFACTS_Production_Branch_BUILDNUMBER

But if you want to use the variable in the build task, don't change to "_", just keep using space. For example:

$(RELEASE.ARTIFACTS.Production Branch.BUILDNUMBER)



回答3:


It looks like you're trying to access it as an environment variable in PowerShell. In PowerShell, the appropriate way to access an environment variable is as $env:RELEASE.ARTIFACTS.Production_Branch.BUILDNUMBER. If that's not exactly it, you can list all of the environment variables and their values with the command gci Env:



来源:https://stackoverflow.com/questions/42002472/how-to-access-an-artifacts-buildnumber-is-visual-studio-team-services-release-m

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