在发布管道(Azure DevOps服务器)中使用Build.Repository.Uri

时间:2019-07-15 08:54:56

标签: azure-devops

我需要在发布管道中使用Build.Repository.Uri。 (将其传递到PowerShell脚本)

在构建管道中:

Write-Host $(Build.Repository.Uri)
> 2019-07-15T08:30:51.8695425Z http://138.202.18.216:8070/Samples/Framework%20A/_git/Framework%20A

在发布管道中:

Write-Host $(Build.Repository.Uri)
> The name Build.Repository.Uri was not recognized as the name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if the path is correct (if included), and try again.

为什么不一致?

我还尝试了Write-Host $(env:BUILD_REPOSITORY_URI),因为:How to read directory path of the Artifact in Release pipeline in Azure DevOps?(我也不明白_背后的逻辑)

是否可以通过发布管道获取Build.Repository.Uri

编辑:解决方案

$env:FRAMEWORKURI -> http://136.202.18.216:8070/Samples/Framework%20A/_git/Framework%20A

如果将system.debug变量设置为true,则在构建后,您可以在Job Initialize(Auftrag initialisieren)报告中找到所有预定义变量。

要将变量作为参数传递给例如Powershell脚本,您可以简单地使用:'$(FRAMEWORKURI)'

2 个答案:

答案 0 :(得分:1)

要在发布管道中访问构建URI,您需要使用发布变量:

Release.Artifacts.{alias}.BuildURI

{alias}是您在发行版中拥有的工件来源的别名

如果您在PowerShell脚本中访问变量,则需要用下划线替换所有点,例如$env:RELEASE_ARTIFACTS_{alias}_BUILDURI

来源:https://docs.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=batch

答案 1 :(得分:1)

变量 Build.Repository.Uri 是代理作用域的。它可以在脚本中用作环境变量,并在构建任务中用作参数。当您在管道中添加值为true的变量System.Debug时,init作业将记录所有可用的环境变量,其中包括REPOSITORY_URI。

您可以尝试以下变量:

Write-Host $env:BUILD_REPOSITORY_URI

Write-Host $env:RELEASE_ARTIFACTS_{alias}_REPOSITORY_URI

请注意,{alias}是Artifact source alias的大写字母。 enter image description here