diff options
author | 2019-05-12 17:42:22 -0700 | |
---|---|---|
committer | 2019-05-12 17:49:29 -0700 | |
commit | 56e6fbd76f4769d1a4de655ddbffdf599073d585 (patch) | |
tree | 5d3082ecfce2a80c495e587116062e42063c3fad | |
parent | Ensure branches are prefixed with refs/heads/ (diff) |
Fall back to target branch if a commit can't be retrieved
-rw-r--r-- | azure-pipelines.yml | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3df683b..a0f2d49 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -43,14 +43,17 @@ jobs: command: 'login' - script: | - SYSTEM_PULLREQUEST_TARGETBRANCH=refs/heads/"${SYSTEM_PULLREQUEST_TARGETBRANCH#refs/heads/}" BUILD_SOURCEBRANCH=refs/heads/"${BUILD_SOURCEBRANCH#refs/heads/}" - - REQUEST_URL="https://dev.azure.com/python-discord/${SYSTEM_TEAMPROJECTID}/_apis/build/builds?queryOrder=finishTimeDescending&resultFilter=succeeded&\$top=1&repositoryType=${BUILD_REPOSITORY_PROVIDER}&repositoryId=${BUILD_REPOSITORY_NAME}&branchName=${SYSTEM_PULLREQUEST_TARGETBRANCH:-BUILD_SOURCEBRANCH}&api-version=5.0" + REQUEST_URL="https://dev.azure.com/python-discord/${SYSTEM_TEAMPROJECTID}/_apis/build/builds?queryOrder=finishTimeDescending&resultFilter=succeeded&\$top=1&repositoryType=${BUILD_REPOSITORY_PROVIDER}&repositoryId=${BUILD_REPOSITORY_NAME}&branchName=${BUILD_SOURCEBRANCH}&api-version=5.0" echo "Retrieving previous build's commit using $REQUEST_URL" PREV_COMMIT="$(curl -sSL "${REQUEST_URL}" | grep -Po '"sourceVersion":"\K.*?[^\\](?=",)')" - echo "Retrieved $PREV_COMMIT as previous build's commit." + if [[ -z $PREV_COMMIT ]]; then + echo "Could not retrieve the previous build's commit. Falling back to the head of the target branch." + PREV_COMMIT=$SYSTEM_PULLREQUEST_TARGETBRANCH + else + echo "Retrieved $PREV_COMMIT as previous build's commit." + fi if [[ -z $PREV_COMMIT ]] || [[ -n "$(git diff $PREV_COMMIT -- docker/base.Dockerfile)" ]]; then echo "Detected changes in docker/base.Dockerfile" |