处理多个Azure Devops管道 [英] Handling multiple azure devops pipelines

查看:56
本文介绍了处理多个Azure Devops管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个项目中,我有几个天蓝色的devops管道文件.这些文件都在一个子目录中,并称为 azure-pipelines.yml .

重命名:我可以在UI中重命名管道以区别它们...但是我想跳过该手动步骤,并在yml中执行.是否有一个参数-我在文档中找不到它.

工作目录:管道从主目录开始.我可以使用 workingDirectory 来调整脚本步骤的工作目录,这要归功于答案

$(Agent.BuildDirectory)映射到 c:\ agent_work \ 1

%(Build.ArtifactStagingDirectory)映射到 c:\ agent_work \ 1 \ a

$(Build.BinariesDirectory)映射到 c:\ agent_work \ 1 \ b

$(Build.SourcesDirectory)映射到 c:\ agent_work \ 1 \ s

您还可以提交对上述重命名管道的功能请求,并为整个调整工作目录管道(单击建议功能并选择Azure Devops")到Microsoft开发团队.希望他们将来会考虑支持这些功能.

I have several azure devops pipeline files in one project. The files are all in a subdirectory and called azure-pipelines.yml.

Renaming: I can rename the pipelines in the UI to distinguish them... but I would like to skip that manual step and perform that in the yml. Is there a parameter for that - I cannot find it in the docs.

Workdirs: the pipelines start in the main directory. I can adjust the working directory of the script steps with workingDirectory thanks to the answer here. But can we also adjust that for the entire pipeline?

解决方案

There is not a parameter for renaming the pipelines. There are two ways to rename the pipelines. One is to manually rename them from the UI. Another way is through build definition update rest api.

Below is an example in powershell scripts to rename the pipeline through rest api. the scripts first get the build definition by build definition get api. Then assign a new name for the build definition, and update the definition with the new name.

$create = "https://dev.azure.com/{ORG}/{PROJ}/_apis/build/definitions/{DefinitionId}?api-version=5.1"

$PAT="{Person access token}"

$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))

$result = Invoke-RestMethod -Uri $create -Headers @{authorization = "Basic $base64AuthInfo"} -Method get 

$result.name = "YamlPipeline-newName"

$updateBody= $result | ConvertTo-Json -Depth 100

$result7 =  Invoke-RestMethod -Uri $create -Headers @{authorization = "Basic $base64AuthInfo"} -Method put -ContentType application/json -Body $updateBody

You cannot change the workingdirectory for the entire pipeline. You can change the workingdirectory inside the tasks.

And there are predefined variables you can use to refer to the places in the agents. For below example:

$(Agent.BuildDirectory) is mapped to c:\agent_work\1

%(Build.ArtifactStagingDirectory) is mapped to c:\agent_work\1\a

$(Build.BinariesDirectory) is mapped to c:\agent_work\1\b

$(Build.SourcesDirectory) is mapped to c:\agent_work\1\s

You can also submit a feature request for above renaming pipeline and adjust workingdirectory for the entire pipeline(click Suggest a feature and choose Azure Devops) to Microsoft Development team. Hope they will consider supporting these feature in the future.

这篇关于处理多个Azure Devops管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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