From 21d6a28715cf3178eb3dc04916dff141aaac2daf Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 28 Feb 2021 14:24:16 +0100 Subject: [PATCH] root: fix branch Name extraction to work on non PRs --- azure-pipelines.yml | 4 +--- outpost/azure-pipelines.yml | 4 +--- scripts/az_do_set_branch.py | 11 +++++++++++ web/azure-pipelines.yml | 4 +--- 4 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 scripts/az_do_set_branch.py diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e250ddcf8..3bfa83436 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -375,9 +375,7 @@ stages: inputs: targetType: 'inline' script: | - set -x - branchName=$(echo "$(System.PullRequest.SourceBranch)" | sed "s/\//-/g") - echo "##vso[task.setvariable variable=branchName]$branchName" + python ./scripts/az_do_set_branch.py - task: Docker@2 inputs: containerRegistry: 'dockerhub' diff --git a/outpost/azure-pipelines.yml b/outpost/azure-pipelines.yml index eb704da05..2b5a2a13b 100644 --- a/outpost/azure-pipelines.yml +++ b/outpost/azure-pipelines.yml @@ -95,9 +95,7 @@ stages: inputs: targetType: 'inline' script: | - set -x - branchName=$(echo "$(System.PullRequest.SourceBranch)" | sed "s/\//-/g") - echo "##vso[task.setvariable variable=branchName]$branchName" + python ./scripts/az_do_set_branch.py - task: Docker@2 inputs: containerRegistry: 'dockerhub' diff --git a/scripts/az_do_set_branch.py b/scripts/az_do_set_branch.py new file mode 100644 index 000000000..554ba87ab --- /dev/null +++ b/scripts/az_do_set_branch.py @@ -0,0 +1,11 @@ +"""Helper script to get the actual branch name, docker safe""" +import os + +env_pr_branch = "SYSTEM_PULLREQUEST_SOURCEBRANCH" +default_branch = "BUILD_SOURCEBRANCHNAME" + +branch_name = os.environ[default_branch] +if env_pr_branch in os.environ: + branch_name = os.environ[env_pr_branch].replace("/", "-") + +print("##vso[task.setvariable variable=branchName]%s" % branch_name) diff --git a/web/azure-pipelines.yml b/web/azure-pipelines.yml index 024a1d9ad..7acd8c6b5 100644 --- a/web/azure-pipelines.yml +++ b/web/azure-pipelines.yml @@ -75,9 +75,7 @@ stages: inputs: targetType: 'inline' script: | - set -x - branchName=$(echo "$(System.PullRequest.SourceBranch)" | sed "s/\//-/g") - echo "##vso[task.setvariable variable=branchName]$branchName" + python ./scripts/az_do_set_branch.py - task: Docker@2 inputs: containerRegistry: 'dockerhub'