aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2019-05-12 19:40:18 -0700
committerGravatar MarkKoz <[email protected]>2019-05-12 19:40:18 -0700
commit878682a9dc99de4673d20adce68a04a487c32197 (patch)
tree9f886e9642560a438804774dade3a24d331f7ed1
parentRevert "Ensure branches are prefixed with refs/heads/" (diff)
Retrieve commit from pr.sourceSha for PR builds
-rw-r--r--azure-pipelines.yml14
1 files changed, 9 insertions, 5 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 6b28088..c90ac96 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -49,16 +49,20 @@ jobs:
- script: |
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"
+ RESPONSE="$(curl -sSL "${REQUEST_URL}")"
- PREV_COMMIT="$(curl -sSL "${REQUEST_URL}" | grep -Po '"sourceVersion":"\K.*?[^\\](?=",)')"
- 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="origin/$SYSTEM_PULLREQUEST_TARGETBRANCH"
+ if [[ $BUILD_REASON = "PullRequest" ]]; then
+ PREV_COMMIT="$(echo "${RESPONSE}" | grep -Po '"pr.sourceSha":"\K.*?[^\\](?=",)')"
+ 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="origin/$SYSTEM_PULLREQUEST_TARGETBRANCH"
else
- echo "Retrieved $PREV_COMMIT as previous build's commit."
+ PREV_COMMIT="$(echo "${RESPONSE}" | grep -Po '"sourceVersion":"\K.*?[^\\](?=",)')"
fi
if [[ -n $PREV_COMMIT ]]; then
+ echo "Using $PREV_COMMIT to compare diffs."
+
if [[ -z "$(git diff $PREV_COMMIT -- docker/base.Dockerfile)" ]]; then
echo "No changes detected in docker/base.Dockerfile. The base image will not be built."
echo "##vso[task.setvariable variable=BASE_CHANGED]false"