You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.
Overview of the Issue
In gitlab, when i create 2 MR using 2 difference branch but with same HEAD commit, atlantis will only update MR pipeline status for first MR. This is blocking us when we set gitlab repo to enforce pipeline success before merge.
Reproduction Steps
Checkout branch A (head at commit X), and push to gitlab
Open a new MR 1 from branch A
Run atlantis plan on MR 1
Atlantis post a comment with plan result to MR 1
Atlantis update MR 1 pipeline status to success
Run atlantis unlock from MR 1
Checkout another branch B (head also at commit X), and push to gitlab
Create another MR 2 from branch B
Run atlantis plan on MR 2
Atlantis post a comment with plan result to MR 2
Atlantis do not update MR 2 pipeline status (it keep showing Checking pipeline status.
Logs
Logs
[DBUG] Getting GitLab merge request 84
[DBUG] GET /projects/<repo_url>/merge_requests/84 returned: 200
[INFO] Pre-workflow hooks configured, running...
[DBUG] got workspace lock
[DBUG] clone directory '/home/atlantis/.atlantis/repos/<repo_url>/84/default' already exists, checking if it's at the right commit
[DBUG] repo is at correct commit '888407c1cf7a31adb584c17b0a1bfc6c6efef6df' so will not re-clone
[INFO] Updating GitLab commit status for 'atlantis-nonprod/plan' to 'running'
[DBUG] GET /projects/gitlab.com/<repo_url>/repository/commits/%!d(string=888407c1cf7a31adb584c17b0a1bfc6c6efef6df): 200
[INFO] Pipeline found for commit 888407c1cf7a31adb584c17b0a1bfc6c6efef6df, setting pipeline ID to 1618879816
[DBUG] Processing pre workflow hook 'Generate repo config', Command 'plan', Target commands []
[DBUG] Running pre workflow hook: 'Generate repo config'
[DBUG] Setting shell to default: ''
[DBUG] Setting shellArgs to default: ''
[INFO] Updating GitLab commit status for 'atlantis-nonprod/pre_workflow_hook: Generate repo config' to 'running'
[DBUG] GET /projects/gitlab.com/<repo_url>/repository/commits/%!d(string=888407c1cf7a31adb584c17b0a1bfc6c6efef6df): 200
[INFO] Pipeline found for commit 888407c1cf7a31adb584c17b0a1bfc6c6efef6df, setting pipeline ID to 1618879816
[INFO] Updating GitLab commit status for 'atlantis-nonprod/pre_workflow_hook: Generate repo config' to 'success'
[DBUG] GET /projects/gitlab.com/<repo_url>/repository/commits/%!d(string=888407c1cf7a31adb584c17b0a1bfc6c6efef6df): 200
[INFO] Pipeline found for commit 888407c1cf7a31adb584c17b0a1bfc6c6efef6df, setting pipeline ID to 1618879816
[INFO] Pre-workflow hooks completed successfully
[DBUG] Checking if GitLab merge request 84 is approved
[DBUG] GET /projects/<repo_url>/merge_requests/84/approvals returned: 200
[DBUG] Checking if GitLab merge request 84 is mergeable
[DBUG] GET /projects/<repo_url>/merge_requests/84 returned: 200
[DBUG] GET /projects/42481065 returned: 200
[DBUG] GET /projects/42481065/commits/888407c1cf7a31adb584c17b0a1bfc6c6efef6df/statuses returned: 200
[INFO] Updating GitLab commit status for 'atlantis-nonprod/plan' to 'running'
[DBUG] GET /projects/gitlab.com/<repo_url>/repository/commits/%!d(string=888407c1cf7a31adb584c17b0a1bfc6c6efef6df): 200
[INFO] Pipeline found for commit 888407c1cf7a31adb584c17b0a1bfc6c6efef6df, setting pipeline ID to 1618879816
[WARN] unable to update commit status: POST https://gitlab.com/api/v4/projects/<repo_url>/statuses/888407c1cf7a31adb584c17b0a1bfc6c6efef6df: 400 {message: Cannot transition status via :run from :running (Reason(s): Status cannot transition via "run")}
[DBUG] Building plan command for all affected projects
[DBUG] Getting modified files for GitLab merge request 84
[DBUG] GET projects/<repo_url>/merge_requests/84/changes returned: 200
[DBUG] 1 files were modified in this pull request. Modified files: [nonprod.terraform.tfvars.yaml]
[DBUG] got workspace lock
[DBUG] clone directory '/home/atlantis/.atlantis/repos/<repo_url>/84/default' already exists, checking if it's at the right commit
[DBUG] repo is at correct commit '888407c1cf7a31adb584c17b0a1bfc6c6efef6df' so will not re-clone
[INFO] successfully parsed atlantis.yaml file
[DBUG] moduleInfo for '/home/atlantis/.atlantis/repos/<repo_url>/84/default' (matching '') = map[]
[DBUG] found downstream projects for "nonprod.terraform.tfvars.yaml": []
[DBUG] checking if project at dir "." workspace "nonprod" was modified
[DBUG] file "nonprod.terraform.tfvars.yaml" matched pattern
[INFO] 1 projects are to be planned based on their when_modified config
[DBUG] determining config for project at dir: '.' workspace: 'nonprod'
[DBUG] MergeProjectCfg started
[DBUG] setting import_requirements: [approved,mergeable,undiverged] from repos[1], id: /gitlab\.com\/<repo_group>\/.*/
[DBUG] setting repo_locks: this is a bug from default server config
[DBUG] setting plan_requirements: [undiverged] from repos[1], id: /gitlab\.com\/<repo_group>\/.*/
[DBUG] setting workflow: "default" from default server config
[DBUG] setting allowed_overrides: [workflow] from repos[1], id: /gitlab\.com\/<repo_group>\/.*/
[DBUG] setting allow_custom_workflows: false from default server config
[DBUG] setting delete_source_branch_on_merge: true from repos[1], id: /gitlab\.com\/<repo_group>\/.*/
[DBUG] setting policy_check: false from default server config
[DBUG] setting custom_policy_check: false from default server config
[DBUG] setting apply_requirements: [approved,mergeable,undiverged] from repos[1], id: /gitlab\.com\/<repo_group>\/.*/
[DBUG] overriding server-defined workflow with repo-specified workflow: "bpv1"
[DBUG] MergeProjectCfg completed
[DBUG] final settings: plan_requirements: [undiverged], apply_requirements: [approved,mergeable,undiverged], import_requirements: [approved,mergeable,undiverged], workflow: bpv1, delete_source_branch_on_merge: true, repo_locking: on_plan, policy_check: false, custom_policy_check: false, silence_pr_comments: []
[DBUG] Building project command context for plan
[INFO] cannot determine which version to use from terraform configuration, detected 0 possibilities.
[DBUG] deleting previous plans and locks
[INFO] Updating GitLab commit status for 'atlantis-nonprod/plan: nonprod' to 'running'
[DBUG] GET /projects/gitlab.com/<repo_url>/repository/commits/%!d(string=888407c1cf7a31adb584c17b0a1bfc6c6efef6df): 200
[INFO] Pipeline found for commit 888407c1cf7a31adb584c17b0a1bfc6c6efef6df, setting pipeline ID to 1618879816
[INFO] Acquired lock with id '<repo_url>/./nonprod'
[DBUG] acquired lock for project
[DBUG] clone directory '/home/atlantis/.atlantis/repos/<repo_url>/84/nonprod' already exists, checking if it's at the right commit
[DBUG] repo is at correct commit '888407c1cf7a31adb584c17b0a1bfc6c6efef6df' so will not re-clone
[INFO] Updating GitLab commit status for 'atlantis-nonprod/plan: nonprod' to 'success'
[DBUG] GET /projects/gitlab.com/<repo_url>/repository/commits/%!d(string=888407c1cf7a31adb584c17b0a1bfc6c6efef6df): 200
[INFO] Pipeline found for commit 888407c1cf7a31adb584c17b0a1bfc6c6efef6df, setting pipeline ID to 1618879816
[INFO] plan success. output available at: https://gitlab.com/<repo_url>/-/merge_requests/84
[DBUG] hiding previous plan comments for command: 'Plan', directory: ''
[DBUG] Hiding previous command comments on GitLab merge request 84
[DBUG] /projects/<repo_url>/merge_requests/84/notes
[DBUG] GET /projects/<repo_url>/merge_requests/84/notes returned: 200
[DBUG] Updating merge request note: Repo: '<repo_url>', MR: '84', comment ID: '2290094251'
[DBUG] PUT /projects/<repo_url>/merge_requests/84/notes/2290094251 returned: 200
I try to investigate from the log, and it seems this bug is happen because atlantis found out that there was another pipeline for the commit X already (despite it's from another branch), and will try to use it instead of creating another one for different MR.
I think we can fix this by checking if the last pipeline was indeed from the same ref first. If the last pipeline was from different branch (ref), then try to create one instead.
example Gitlab API GET /projects/%s/repository/commits/%d response
@orhan89 Hello! I'm here to help you with any issues, answer questions, and even guide you on how to become a contributor. Let me know how I can assist you with your current concern.
In your case, the problem seems to be that Atlantis is reusing an existing pipeline for a commit shared across multiple branches, which leads to the pipeline status not being updated for the second merge request. The proposed solution is to modify the logic to ensure that the last pipeline belongs to the same branch before reusing it. If the last pipeline is from a different branch, Atlantis should create a new pipeline for the second merge request. This involves checking the last_pipeline field in the GitLab API response to verify the branch (ref) before proceeding with the status update.
Community Note
Overview of the Issue
In gitlab, when i create 2 MR using 2 difference branch but with same HEAD commit, atlantis will only update MR pipeline status for first MR. This is blocking us when we set gitlab repo to enforce pipeline success before merge.
Reproduction Steps
atlantis plan
on MR 1atlantis unlock
from MR 1atlantis plan
on MR 2Checking pipeline status.
Logs
Logs
PS: I have retract some information from the log
Environment details
Atlantis server-side config file:
Additional Context
I try to investigate from the log, and it seems this bug is happen because atlantis found out that there was another pipeline for the commit X already (despite it's from another branch), and will try to use it instead of creating another one for different MR.
atlantis/server/events/vcs/gitlab_client.go
Lines 424 to 446 in de1d8dc
I think we can fix this by checking if the last pipeline was indeed from the same ref first. If the last pipeline was from different branch (ref), then try to create one instead.
example Gitlab API GET /projects/%s/repository/commits/%d response
The text was updated successfully, but these errors were encountered: