From 20a04f081a90ab4911a280d1cd10e6435ba0a0af Mon Sep 17 00:00:00 2001 From: Alina Heinze Date: Wed, 6 Jul 2022 16:18:57 +0200 Subject: [PATCH] new step in pipeline for creating new integration and delete merged branches --- .gitlab-ci.yml | 9 +++++++ .../cleanUpAndCreateBranches.ps1 | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 deployment-scripts/cleanUpAndCreateBranches.ps1 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 92c650c..c84764e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,6 +6,7 @@ stages: - build - openMr - deploy + - cleanUpAndCreateBranches build: stage: build @@ -22,6 +23,14 @@ openMr: script: - '&".\deployment-scripts\openMr.ps1" -api "https://git.rwth-aachen.de/api/v4/" -project ${CI_PROJECT_ID} -branch ${CI_COMMIT_REF_NAME} -user ${GITLAB_USER_ID} -token ${openMrToken} -queryTargetBranch "^integration"' +cleanUpAndCreateBranches: + tags: ["env:devlef"] + stage: cleanUpAndCreateBranches + only: [dev] + script: + - '&".\deployment-scripts\cleanUpAndCreateBranches.ps1" -api "https://git.rwth-aachen.de/api/v4/" -project ${CI_PROJECT_ID} -user ${GITLAB_USER_ID} -token ${openMrToken}' + when: manual + build_integration: stage: build only: [/^integration/.*$/] diff --git a/deployment-scripts/cleanUpAndCreateBranches.ps1 b/deployment-scripts/cleanUpAndCreateBranches.ps1 new file mode 100644 index 0000000..b05e330 --- /dev/null +++ b/deployment-scripts/cleanUpAndCreateBranches.ps1 @@ -0,0 +1,24 @@ +param( + [string] $api, + [string] $project, + [string] $user, + [string] $token +) + +$queriedIntegrationBranches = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "projects/" + $project + "/repository/branches?search=^integration") +$queriedIntegrationBranch = $queriedIntegrationBranches | Sort name -desc | Select -First 1 + +$integrationBranchName = $queriedIntegrationBranch.Name + +$splittedBranchName= $integrationBranchName -split '-' +$currentBranchNumber = $splittedBranchName[$splittedBranchName.Length-1] + +if($currentBranchNumber -match "^\d+$") +{ + $currentBranchNumber = $currentBranchNumber -as [int] + $currentBranchNumber++ + $answer = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Post -Uri ($api + "projects/" + $project + "/repository/branches?branch=integration/sprint-" + $splittedBranchName[$splittedBranchName.Length-2] + "-" + $currentBranchNumber + "&ref=dev") + Write $answer +} +$deleteAnswer = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Delete -Uri ($api + "projects/" + $project + "/repository/merged_branches") +Write $deleteAnswer -- GitLab