aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2019-06-23 16:26:53 -0700
committerGravatar MarkKoz <[email protected]>2019-06-29 20:05:36 -0700
commit4ab5d46e13ab910b8e28f27b2ce16d5cd979a9e2 (patch)
treeac564ff23cab265110ccec9dfacaf588549bafea
parentGet previous build ID (diff)
Echo variables
-rw-r--r--azure-pipelines.yml28
1 files changed, 18 insertions, 10 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index db11c70..1a7d3ad 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -9,6 +9,8 @@ jobs:
steps:
- script: |
+ set -euo pipefail
+
REQUEST_URL="https://dev.azure.com/\
python-discord/${SYSTEM_TEAMPROJECTID}/_apis/build/builds?\
queryOrder=finishTimeDescending&\
@@ -22,26 +24,32 @@ jobs:
printf '%s\n' "Retrieving latest successful build using ${REQUEST_URL}"
response="$(curl -sSL "${REQUEST_URL}")"
+ if [[ "$(printf '%s' "${response}" | jq -re '.count')" = 0 ]]; then
+ (>&2 echo \
+ "No previous build was found." \
+ "Either the previous build is too old and was deleted" \
+ "or the branch was empty before this build."
+ )
+ exit 0
+ fi
+
prev_build="$(printf '%s' "${response}" | jq -re '.value[0].id')"
- printf '%s\n' "Most recent successful build found: ${prev_build}"
+ printf '%s\n' "Most recent successful build: ${prev_build}"
printf '%s\n' "##vso[task.setvariable variable=PREV_BUILD]${prev_build}"
if [[ "${BUILD_REASON}" = "PullRequest" ]]; then
- prev_commit="$(printf '%s' "${response}" | jq -re '.value[0]."pr.sourceSha"')"
-
- 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}"
- fi
+ key='triggerInfo."pr.sourceSha"'
else
- prev_commit="$(printf '%s' "${response}" | jq -re '.value[0].sourceVersion')"
+ key='sourceVersion'
fi
+ prev_commit="$(printf '%s' "${response}" | jq -re ".value[0].${key}")"
+ printf '%s\n' "Previous commit: ${prev_commit}"
printf '%s\n' "##vso[task.setvariable variable=PREV_COMMIT]${prev_commit}"
displayName: 'Get Previous Successful Build'
+ - script: echo $(PREV_BUILD) && echo $(PREV_COMMIT)
+
- task: DownloadPipelineArtifact@1
inputs:
source: 'specific'