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.
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
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…