mmajcica / retain-release

Azure DevOps Extension containing a release task that will mark the current release to be retained indefinitely
MIT License
5 stars 4 forks source link

Option: Also retain the run of the CI pipeline which the retained run of the CD pipeline depends on #7

Open afeblot opened 4 years ago

afeblot commented 4 years ago

When a release pipeline run is retained, Azure DevOps automatically retains the run of the build pipeline that is used by the release. Similarly, we can now have a multistage CD pipeline which is triggered by a distinct CI pipeline, and which deploys artifacts produced by this CI pipeline. If would be awesome to have an option for retaining as well the run of the CI pipeline when the task is executed in the CD pipeline. The task would just need the CI pipeline resource alias as an input, allowing to get the CI pipeline project, id, and run id with these predefined variables:

afeblot commented 4 years ago

For the record, here is how I did it with no extension:

            - bash: |
                set -e -o pipefail
                resp=$(curl -Ss -u :$(System.AccessToken) -X PATCH -H "Content-Type: application/json" --data '{"keepForever": true}' $(System.CollectionUri)$(System.TeamProject)/_apis/build/builds/$(Build.BuildId)?api-version=5.1)
                if [[ $(echo "$resp" | jq -r '.keepForever') != true ]]; then
                  echo "$resp" | jq -r .
                  echo "##vso[task.logissue type=error]Could not retain forever this pipeline execution."
                  exit 1
                fi
                echo "Pipeline execution retained."

                # Retain as well the build which produced the artifact deployed by this pipeline
                resp=$(curl -Ss -u :$(System.AccessToken) -X PATCH -H "Content-Type: application/json" --data '{"retainedByRelease": true}' $(System.CollectionUri)$(System.TeamProject)/_apis/build/builds/$(resources.pipeline.${{parameters.mainArtifactName}}.runID)?api-version=5.1)
                if [[ $(echo "$resp" | jq -r '.retainedByRelease') != true ]]; then
                  echo "$resp" | jq -r .
                  echo "##vso[task.logissue type=error]Could not retain forever the build execution ($(resources.pipeline.${{parameters.mainArtifactName}}.runID)) which produced the artifact deployed by this pipeline"
                  exit 1
                fi
                echo "Build pipeline execution retained (build id : $(resources.pipeline.${{parameters.mainArtifactName}}.runID))"
              condition: succeeded()
              displayName: Retain forever the release and associated build