diff options
| author | 2019-06-23 15:39:59 -0700 | |
|---|---|---|
| committer | 2019-06-29 20:05:36 -0700 | |
| commit | 1d3645351bef58129f640b5d3c22015fff8cbbdb (patch) | |
| tree | b1d0561fe23b84452ab0f75b6a8672c5f52e2a78 | |
| parent | Yes (diff) | |
Get previous build ID
| -rw-r--r-- | azure-pipelines.yml | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 28ec742..db11c70 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,9 +8,57 @@ jobs: vmImage: 'Ubuntu-16.04' steps: + - 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" + + printf '%s\n' "Retrieving latest successful build using ${REQUEST_URL}" + response="$(curl -sSL "${REQUEST_URL}")" + + prev_build="$(printf '%s' "${response}" | jq -re '.value[0].id')" + printf '%s\n' "Most recent successful build found: ${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 + else + prev_commit="$(printf '%s' "${response}" | jq -re '.value[0].sourceVersion')" + fi + + printf '%s\n' "##vso[task.setvariable variable=PREV_COMMIT]${prev_commit}" + displayName: 'Get Previous Successful Build' + + - task: DownloadPipelineArtifact@1 + inputs: + source: 'specific' + project: $(System.TeamProject) + pipeline: $(System.DefinitionId) + runVersion: 'specific' + buildId: $(PREV_BUILD) + artifactName: 'BaseId' + displayName: 'Download Base ID Artifact' + + - script: | + base_id="$(cat "${SYSTEM_ARTIFACTSDIRECTORY}"/base.sha256)" + printf '%s\n' "##vso[task.setvariable variable=BASE_ID]${base_id}" + displayName: 'Write Base ID to Variable' + - script: docker build -t pythondiscord/snekbox-base:latest -f docker/base.Dockerfile . displayName: 'Build Base Image' - enabled: false - script: | id="$(docker images -q --no-trunc pythondiscord/snekbox-base:latest)" @@ -20,26 +68,10 @@ jobs: fi printf '%s' "${id}" >> base.sha256 - displayName: 'Create Digest Artifact' - enabled: false + displayName: 'Create Base ID Artifact' - task: PublishPipelineArtifact@1 inputs: path: base.sha256 - artifact: base_id - enabled: false - - - task: DownloadPipelineArtifact@1 - inputs: - buildType: 'specific' - project: $(System.TeamProject) - pipeline: $(System.DefinitionId) - buildVersionToDownload: 'specific' - buildId: 2434 - artifactName: 'base_id' - - - script: | - ls -la $(System.ArtifactsDirectory) - - - script: | - cat $(System.ArtifactsDirectory)/base.sha256 + artifact: BaseId + displayName: 'Publish Base ID Artifact' |