From b3a38b226148e50fd7a327e0dd96efdbb5be6e50 Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Tue, 27 Jul 2021 15:21:13 -0700 Subject: [PATCH] Add ability to leave SourceBranch empty when queueing a build (builds using the default branch) --- eng/common/scripts/Invoke-DevOpsAPI.ps1 | 1 - eng/common/scripts/Queue-Pipeline.ps1 | 47 +++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/eng/common/scripts/Invoke-DevOpsAPI.ps1 b/eng/common/scripts/Invoke-DevOpsAPI.ps1 index 72d61edd081..41f4796d42f 100644 --- a/eng/common/scripts/Invoke-DevOpsAPI.ps1 +++ b/eng/common/scripts/Invoke-DevOpsAPI.ps1 @@ -13,7 +13,6 @@ function Start-DevOpsBuild { param ( $Organization="azure-sdk", $Project="internal", - [Parameter(Mandatory = $true)] $SourceBranch, [Parameter(Mandatory = $true)] $DefinitionId, diff --git a/eng/common/scripts/Queue-Pipeline.ps1 b/eng/common/scripts/Queue-Pipeline.ps1 index 30a4282c8cb..07d12efd838 100644 --- a/eng/common/scripts/Queue-Pipeline.ps1 +++ b/eng/common/scripts/Queue-Pipeline.ps1 @@ -1,3 +1,45 @@ +<# +.SYNOPSIS +Queues an Azure DevOps Pipeline run optionally canceling similar runs + +.PARAMETER Organization +Azure DevOps organization name + +.PARAMETER Project +Azure DevOps project name + +.PARAMETER SourceBranch +Source branch use when executing the DevOps pipeline. Specifying an empty string +will result in queuing of the run with the default branch configured for the +pipeline. + +.PARAMETER DefinitionId +Pipline definition ID + +.PARAMETER CancelPreviousBuilds +Requires a value for SourceBranch. Cancel previous builds before queuing the new +build. + +.PARAMETER VsoQueuedPipelines +Variable name to set in DevOps for the queued pipeline links + +.PARAMETER Base64EncodedAuthToken +Auth token for Azure DevOps API + +.PARAMETER BuildParametersJson +Additional build parameters to provide to the pipeline execution. + +Of the format: + +```json +{ + "variable1": "value1", + "variable2": "value2" +} +``` + +#> + [CmdletBinding(SupportsShouldProcess = $true)] param( [Parameter(Mandatory = $true)] @@ -6,7 +48,6 @@ param( [Parameter(Mandatory = $true)] [string]$Project, - [Parameter(Mandatory = $true)] [string]$SourceBranch, [Parameter(Mandatory = $true)] @@ -26,7 +67,9 @@ param( . (Join-Path $PSScriptRoot common.ps1) -if ($CancelPreviousBuilds) +# Skip if SourceBranch is empty because it we cannot generate a target branch +# name from an empty string. +if ($CancelPreviousBuilds -and $SourceBranch) { try { $queuedBuilds = Get-DevOpsBuilds -BranchName "refs/heads/$SourceBranch" -Definitions $DefinitionId `