diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c451e61fa53115a27c0caf9842e5d1ff27d37b87..8718a0bb2f5c52f80e8b3b1f06e76545bc17759f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,7 +6,7 @@ stages: - build - openMr - deploy - - cleanUpAndCreateBranches + - cleanupAndCreateBranches build: stage: build @@ -21,13 +21,13 @@ openMr: stage: openMr except: [master, dev, /^integration/.*$/] 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"' + - '&".\deployment-scripts\open-mr.ps1" -api ${CI_API_V4_URL} -project ${CI_PROJECT_ID} -branch ${CI_COMMIT_REF_NAME} -user ${GITLAB_USER_ID} -token ${groupApiToken} -queryTargetBranch "^integration"' -cleanUpAndCreateBranches: - stage: cleanUpAndCreateBranches +cleanupAndCreateBranches: + 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}' + - '&".\deployment-scripts\cleanup-and-create-branches.ps1" -api ${CI_API_V4_URL} -project ${CI_PROJECT_ID} -user ${GITLAB_USER_ID} -token ${groupApiToken}' when: manual build_integration: diff --git a/deployment-scripts/cleanUpAndCreateBranches.ps1 b/deployment-scripts/cleanup-and-create-branches.ps1 similarity index 61% rename from deployment-scripts/cleanUpAndCreateBranches.ps1 rename to deployment-scripts/cleanup-and-create-branches.ps1 index b05e330cb0cbb21e98b4add56141c2a7992e81a9..ca02c48f8d7f52bcdb531252ef96ef81290c7525 100644 --- a/deployment-scripts/cleanUpAndCreateBranches.ps1 +++ b/deployment-scripts/cleanup-and-create-branches.ps1 @@ -5,7 +5,7 @@ param( [string] $token ) -$queriedIntegrationBranches = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "projects/" + $project + "/repository/branches?search=^integration") +$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 @@ -17,8 +17,8 @@ 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") + $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") +$deleteAnswer = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Delete -Uri ($api + "/projects/" + $project + "/repository/merged_branches") Write $deleteAnswer diff --git a/deployment-scripts/openMr.ps1 b/deployment-scripts/open-mr.ps1 similarity index 76% rename from deployment-scripts/openMr.ps1 rename to deployment-scripts/open-mr.ps1 index 504d62caf29ad008996f9e64ce643b0b32469340..9eed23873d0addb7b9c24181fded4ec6a07cd094 100644 --- a/deployment-scripts/openMr.ps1 +++ b/deployment-scripts/open-mr.ps1 @@ -8,7 +8,7 @@ param( ) # check if mr target branch already exists -$queriedTargetBranches = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "projects/" + $project + "/repository/branches?search=$queryTargetBranch") +$queriedTargetBranches = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "/projects/" + $project + "/repository/branches?search=$queryTargetBranch") $queriedTargetBranch = $queriedTargetBranches | Sort name -desc | Select -First 1 if ($queriedTargetBranch -eq $null) { @@ -18,7 +18,7 @@ if ($queriedTargetBranch -eq $null) { $queriedTargetBranchName = $queriedTargetBranch.Name # check if mr already exists -$openedMRs = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "projects/" + $project + "/merge_requests?state=opened") +$openedMRs = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -Method Get -Uri ($api + "/projects/" + $project + "/merge_requests?state=opened") $openedMR = $openedMRs | Where source_branch -eq $branch | Select -First 1 if ($openedMR -eq $null) { @@ -32,7 +32,7 @@ if ($openedMR -eq $null) { } # create mr - $createResponse = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -ContentType "application/json" -Method Post -Uri ($api + "projects/" + $project + "/merge_requests") -Body (ConvertTo-Json $body) + $createResponse = Invoke-RestMethod -Headers @{ 'PRIVATE-TOKEN'="$token" } -ContentType "application/json" -Method Post -Uri ($api + "/projects/" + $project + "/merge_requests") -Body (ConvertTo-Json $body) echo "Opened a new merge request: 'Draft: $branch' and assigned to you"; exit }