Handling multiple azure devops pipelines

a 夏天 提交于 2021-01-29 21:34:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/60036020/handling-multiple-azure-devops-pipelines

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