如何在Azure DevOps中的发布管道中读取工件的目录路径? [英] How to read directory path of the Artifact in Release pipeline in Azure DevOps?

查看:224
本文介绍了如何在Azure DevOps中的发布管道中读取工件的目录路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在Release管道的PowerShell任务中显示工件的目录路径. 在构建管道中,工件的目录由变量$(System.DefaultWorkingDirectory)描述,如果我尝试显示它, 在PowerShell任务中,使用命令

I want to be able to display a directory path of the Artifact in the PowerShell task in the Release pipeline. In the build pipeline, the directory of the Artifact is described by the variable $(System.DefaultWorkingDirectory) and if I try to display it in the PowerShell task using the command

Write-Host $(System.DefaultWorkingDirectory)

在控制台输出中,

显示路径C:\agent\_work\3\a. 该变量在Release管道中以及我运行命令时都不存在

in the console output, it shows the path C:\agent\_work\3\a. This variable doesn't exist in the Release pipeline and when I run the command

Get-ChildItem Env:

在powerhsell任务的发布管道中,我可以看到所有环境变量,但是没有一个变量存储C:\agent\_work\3\a path 我如何获取它,因为在执行Artifact下载过程时,AgentJob会以某种方式知道Artifact的正确目录. 有任何想法吗?干杯

in the powerhsell task, in the release pipeline, I can see all environemnt variables but none of the variables stores the C:\agent\_work\3\a path How can i get it, cuz somehow the AgentJob knows the proper directory of the Artifact when doing the Artifact downloading process. Any ideas? Cheers

推荐答案

在脚本中将构建和发布变量作为环境变量访问时,您需要将.替换为_.

When accessing build and release variables as environment variables within scripts, you need to replace . with _. This is explained in the documentation. In PowerShell, you'd access $env:SYSTEM_DEFAULTWORKINGDIRECTORY.

变量 名称将转换为大写,并将字符."转换为大写.和"是 替换为"_".

Variable names are transformed to uppercase, and the characters "." and " " are replaced by "_".

例如,Agent.WorkFolder成为AGENT_WORKFOLDER.在Windows上, 您可以以%AGENT_WORKFOLDER或$ env:AGENT_WORKFOLDER的身份进行访问.在 在Linux和macOS上,您使用$ AGENT_WORKFOLDER.

For example, Agent.WorkFolder becomes AGENT_WORKFOLDER. On Windows, you access this as %AGENT_WORKFOLDER or $env:AGENT_WORKFOLDER. On Linux and macOS, you use $AGENT_WORKFOLDER.

这篇关于如何在Azure DevOps中的发布管道中读取工件的目录路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆