Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

git - Azure DevOps Releases get pipeline build across branches

We have a product that we build through Azure DevOps. This product is made up of about 20 different services that each get built in their own pipelines. At the end of each pipeline we push the output (a docker image) to an Azure Container Registry using the Build ID as the ID for that image.

We then have a DevOps Release that deploys to our Test (and then Prod) environments. It looks for the latest build for each pipeline and uses that ID to determine the relevant image to deploy for each service.

I'm now trying to build a build a new DevOps Release that will allow our QA team to deploy a given Branch to a new QA environment. I want the user to be able to select a Branch and for DevOps to determine the last build for each pipeline for that specific branch - or if that branch has never been built for a given pipeline then to fallback to the last Master branch build for that pipeline.

I can't see how to add a Branch variable that will then re-calculate the Artifacts when triggering a manual build. And, while I can get it to find the latest build for a particular branch but no way of getting it to fall back to Master if no build has been done for that Branch.

Is it possible to do this? If not, is there another approach to achieving the same outcome?

question from:https://stackoverflow.com/questions/65877837/azure-devops-releases-get-pipeline-build-across-branches

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm now trying to build a build a new DevOps Release that will allow our QA team to deploy a given Branch to a new QA environment. I want the user to be able to select a Branch and for DevOps to determine the last build for each pipeline for that specific branch

You are creating a new release pipeline definition to deploy QA environment, and this release pipeline only deploy QA environment, right? If yes, we could configure the stage Pre-deployment conditions. Steps: Open Pre-deployment conditions->enable Artifact filters, check the pic below.

enter image description here

I can't see how to add a Branch variable that will then re-calculate the Artifacts when triggering a manual build. And, while I can get it to find the latest build for a particular branch but no way of getting it to fall back to Master if no build has been done for that Branch.

We could add task bash and enter the script printenv to list all variable and check the build source branch. Check the below sample, we could get the latest master branch build ID if no build has been done for that Branch.

$URL="https://dev.azure.com/{Org name}/{project name}/_apis/build/Builds?branchName=refs/heads/{target branch}&definitions={build definition ID}"
$PAT="{PAT}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))

$Result = Invoke-RestMethod -Uri $URL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
If($Result.count -eq "0")
{
#back to Master if no build has been done for the target Branch 
$MasterBranchURL = "https://dev.azure.com/{Org name}/{project name}/_apis/build/Builds?branchName=refs/heads/master&definitions={build definition ID}"
$MasterBranchResult = Invoke-RestMethod -Uri $MasterBranchURL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get

    foreach($Build in $MasterBranchResult.value){
       If($Build.result -eq "succeeded"){
       #Get the master branch latest success build ID
       $ID = $Build.id
       echo "##vso[task.setvariable variable=BuildID;isOutput=true]$ID"
       break
       }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...