diff options
| -rw-r--r-- | azure-pipelines.yml | 14 | 
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" | 
