From e65930a7471c1d1074902f022234807bb7a84ccf Mon Sep 17 00:00:00 2001 From: John Cai Date: Tue, 18 Jul 2023 11:09:41 -0400 Subject: [PATCH] .gitlab-ci.yml: Use an environment to automatically clean up branches --- .gitlab-ci.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 64e13fcb00..efe5eb2cd2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -528,6 +528,9 @@ start-rails-specs: --data "content=$CI_MERGE_REQUEST_SOURCE_BRANCH_SHA" \ --data "commit_message=Updating GITALY_SERVER_VERSION to $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA" \ https://gitlab.com/api/v4/projects/278964/repository/files/GITALY_SERVER_VERSION + environment: + name: merge-requests/$CI_MERGE_REQUEST_IID + on_stop: rails-specs-cleanup rules: - when: manual allow_failure: true @@ -551,6 +554,23 @@ rails-specs-cleanup: - | curl --request DELETE --header "PRIVATE-TOKEN: $GITLAB_PROJECT_TOKEN" \ "https://gitlab.com/api/v4/projects/278964/repository/branches/$RAILS_BRANCH_FOR_MERGE_REQUEST" + environment: + name: merge-requests/$CI_MERGE_REQUEST_IID + action: stop + +cleanup-rails-spec-test-env: + needs: [] + stage: qa + before_script: + - apt update + - apt install -y jq + script: + - | + ENV_ID=$(curl -s --request GET --header "PRIVATE-TOKEN: $GITALY_PROJECT_TOKEN" "https://gitlab.com/api/v4/projects/2009901/environments?name=merge-requests%2F$CI_MERGE_REQUEST_IID" | jq '.[0].id') + curl -s --request DELETE --header "PRIVATE-TOKEN: $GITALY_PROJECT_TOKEN" "https://gitlab.com/api/v4/projects/2009901/environments/$ENV_ID" + rules: + - when: manual + allow_failure: true build-package-and-qa: needs: [] -- GitLab