root: fix branch Name extraction to work on non PRs

This commit is contained in:
Jens Langhammer 2021-02-28 14:24:16 +01:00
parent 1149a8d9a4
commit 21d6a28715
4 changed files with 14 additions and 9 deletions

View File

@ -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'

View File

@ -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'

View File

@ -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)

View File

@ -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'