简体   繁体   中英

Handling multiple azure devops pipelines

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 alsosubmit 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM