Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
afeblot opened this issue Feb 5, 2020 · 1 comment

Comments

@afeblot
Copy link

afeblot commented Feb 5, 2020

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:

  • resources.pipeline.<Alias>.projectID
  • resources.pipeline.<Alias>.pipelineID
  • resources.pipeline.<Alias>.runID
@afeblot afeblot changed the title Option: Also retain the run of the build pipeline which the retained run of the deployment pipeline depends on Option: Also retain the run of the CI pipeline which the retained run of the CD pipeline depends on Mar 9, 2020
@afeblot
Copy link
Author

afeblot commented Apr 8, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant