Skip to content

Commit 7519eea

Browse files
fix gitlab pipeline commit bug
1 parent 0b8fa6e commit 7519eea

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Gitlab-Templatized/.gitlab/ci/generate-deployment-scripts.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,17 @@
150150
- "git diff --cached --stat"
151151
- "git commit -m \"${GIT_COMMIT_MESSAGE}\""
152152
- "if [ -n \"${GIT_PUSH_TOKEN}\" ]; then CURRENT_URL=$(git remote get-url origin); PUSH_URL=$(echo \"${CURRENT_URL}\" | sed \"s|://[^@]*@|://oauth2:${GIT_PUSH_TOKEN}@|\"); git remote set-url origin \"${PUSH_URL}\"; fi"
153+
- "git fetch origin ${CI_COMMIT_REF_NAME}"
154+
- "git rebase origin/${CI_COMMIT_REF_NAME}"
153155
- "git push origin HEAD:${CI_COMMIT_REF_NAME}"
154156
- "echo '--- Creating merge request ---'"
155157
- "API_TOKEN=${GIT_PUSH_TOKEN:-${CI_JOB_TOKEN}}"
156-
- "GITLAB_API_URL=$(git remote get-url origin | sed 's|/[^/]*/[^/]*\\.git$||')/api/v4"
157-
- "EXISTING_MR=$(curl -sf --header \"PRIVATE-TOKEN: ${API_TOKEN}\" \"${GITLAB_API_URL}/projects/${CI_PROJECT_ID}/merge_requests?source_branch=${CI_COMMIT_REF_NAME}&target_branch=${MR_TARGET_BRANCH}&state=opened\" | jq '.[0].iid // empty')"
158-
- "if [ -n \"${EXISTING_MR}\" ]; then echo \"Merge request already exists (MR !${EXISTING_MR})\"; MR_IID=${EXISTING_MR}; else MR_RESPONSE=$(curl -sf --header \"PRIVATE-TOKEN: ${API_TOKEN}\" --header \"Content-Type: application/json\" --data \"{\\\"source_branch\\\": \\\"${CI_COMMIT_REF_NAME}\\\", \\\"target_branch\\\": \\\"${MR_TARGET_BRANCH}\\\", \\\"title\\\": \\\"${MR_TITLE}\\\", \\\"remove_source_branch\\\": false}\" \"${GITLAB_API_URL}/projects/${CI_PROJECT_ID}/merge_requests\"); MR_IID=$(echo \"${MR_RESPONSE}\" | jq -r .iid); fi"
158+
- "GITLAB_API_URL=$(git remote get-url origin | sed 's|://[^@]*@|://|; s|\\.git$||; s|/[^/]*/[^/]*$||')/api/v4"
159+
- "echo \"API URL: ${GITLAB_API_URL}\""
160+
- "MR_RESPONSE=$(curl -s --header \"PRIVATE-TOKEN: ${API_TOKEN}\" \"${GITLAB_API_URL}/projects/${CI_PROJECT_ID}/merge_requests?source_branch=${CI_COMMIT_REF_NAME}&target_branch=${MR_TARGET_BRANCH}&state=opened\")"
161+
- "echo \"MR lookup response: ${MR_RESPONSE}\""
162+
- "EXISTING_MR=$(echo \"${MR_RESPONSE}\" | jq -r 'if type == \"array\" then (.[0].iid // empty) else empty end')"
163+
- "if [ -n \"${EXISTING_MR}\" ]; then echo \"Merge request already exists (MR !${EXISTING_MR})\"; MR_IID=${EXISTING_MR}; else MR_RESPONSE=$(curl -s --header \"PRIVATE-TOKEN: ${API_TOKEN}\" --header \"Content-Type: application/json\" --data \"{\\\"source_branch\\\": \\\"${CI_COMMIT_REF_NAME}\\\", \\\"target_branch\\\": \\\"${MR_TARGET_BRANCH}\\\", \\\"title\\\": \\\"${MR_TITLE}\\\", \\\"remove_source_branch\\\": false}\" \"${GITLAB_API_URL}/projects/${CI_PROJECT_ID}/merge_requests\"); echo \"MR create response: ${MR_RESPONSE}\"; MR_IID=$(echo \"${MR_RESPONSE}\" | jq -r .iid); fi"
159164
- "BROWSE_URL=${GITLAB_EXTERNAL_URL:-${CI_SERVER_URL}}/${CI_PROJECT_PATH}/-/merge_requests/${MR_IID}"
160165
- "echo '========================================'"
161166
- "echo \"Review and merge: ${BROWSE_URL}\""

0 commit comments

Comments
 (0)