Skip to content

Commit

Permalink
[Azure Pipelines] Manually extract the full branch name
Browse files Browse the repository at this point in the history
"Build.SourceBranchName does not include full name, if name includes forward slash"
  • Loading branch information
past-due committed Feb 25, 2020
1 parent 31a0e7f commit a7a1570
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .azure/templates/macos-build-pipeline-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ jobs:

steps:
- template: prepare-repo-steps.yml
- task: CmdLine@2
displayName: Compute additional variables
# See: "Build.SourceBranchName does not include full name, if name includes forward slash"
# - Link: https://github.com/microsoft/azure-pipelines-agent/issues/838
# Also see: https://medium.com/microsoftazure/how-to-pass-variables-in-azure-pipelines-yaml-tasks-5c81c5d31763
inputs:
script: |
FULL_SOURCE_BRANCH_NAME=$(echo ${BUILD_SOURCEBRANCHNAME} | sed 's/refs\/[^\/]*\///')
echo "FULL_SOURCE_BRANCH_NAME=${FULL_SOURCE_BRANCH_NAME}"
echo "##vso[task.setvariable variable=FULL_SOURCE_BRANCH_NAME]$FULL_SOURCE_BRANCH_NAME"
- task: CmdLine@2
displayName: Install pre-reqs
inputs:
Expand Down
11 changes: 7 additions & 4 deletions build_tools/autorevision.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,15 @@ macro(_azureCIBuild)
# Use SYSTEM_PULLREQUEST_SOURCEBRANCH to get the source branch
set(VCS_BRANCH "$ENV{SYSTEM_PULLREQUEST_SOURCEBRANCH}")
else()
# In the normal case, use BUILD_SOURCEBRANCHNAME
if (DEFINED ENV{BUILD_SOURCEBRANCHNAME} AND NOT "$ENV{BUILD_SOURCEBRANCHNAME}" STREQUAL "")
set(VCS_BRANCH "$ENV{BUILD_SOURCEBRANCHNAME}")
# In the normal case, we _would_ use BUILD_SOURCEBRANCHNAME... but:
# "Build.SourceBranchName does not include full name, if name includes forward slash"
# - Link: https://github.com/microsoft/azure-pipelines-agent/issues/838
# So, parse the BUILD_SOURCEBRANCH to get the full branch name
if (DEFINED ENV{BUILD_SOURCEBRANCH} AND "$ENV{BUILD_SOURCEBRANCH}" MATCHES "^refs/[^/]*/(.*)")
set(VCS_BRANCH "${CMAKE_MATCH_1}")
else()
if(NOT LOGGING_QUIET)
message( WARNING "BUILD_SOURCEBRANCHNAME is empty; VCS_BRANCH may be empty" )
message( WARNING "BUILD_SOURCEBRANCH is ('${BUILD_SOURCEBRANCH}'); did not parse as expected; VCS_BRANCH may be empty" )
endif()
endif()
endif()
Expand Down

0 comments on commit a7a1570

Please sign in to comment.