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.
this logic leads to an issue for me, after running a plan through API on a target project, the dir created by the plan will be overridden by the apply API call due to the reason {"level":"debug","ts":"2024-11-15T19:01:16.817+0800","caller":"events/working_dir.go:136","msg":"repo was already cloned but is not at correct commit, wanted 'atlantis-api-test' got '6f3b9277ec240d6b6f9521a76caf5374316a1eaf'","json":{}}, source code is here https://github.com/runatlantis/atlantis/blob/main/server/events/working_dir.go#L128-L137 , then Atlantis will do a force clone, this action will clean up the tf status files created by the previous plan, so the apply call always fails due to the error Error running apply operation: no plan found at path \"infra/glue/wap/wap-udp-dev\" and workspace \"default\"–did you run plan?
Hello @jiaflu! I'm here to assist you with any bugs, questions, or contributions you have. Let's work together to resolve any issues you're facing.
The issue you're encountering is due to the BaseBranch, HeadBranch, and HeadCommit in the PullRequest model being set to the same value, request.Ref, when using the Atlantis API. This setup causes problems because the directory created by the plan operation is overridden by the apply operation, leading to the error "no plan found at path" during the apply call.
The root of the problem lies in the logic used in the api_controller.go file, where these fields are incorrectly set to the same value. This results in the repository not being at the correct commit, as indicated by the debug message you provided.
In contrast, when the plan is triggered by events, the correct PR details are obtained using different logic in the event_parser.go file. This discrepancy in handling PR details between API calls and event-triggered operations is causing the issue.
To resolve this, the logic in the api_controller.go file needs to be adjusted to correctly set the BaseBranch, HeadBranch, and HeadCommit values based on the actual PR details, similar to how it's done in the event_parser.go file. This would ensure that the plan and apply operations are executed on the correct commit and branch, preventing the directory from being overridden incorrectly.
Community Note
Overview of the Issue
Hi, Atlantis team, I've been testing Atlantis API endpoints following the doc https://www.runatlantis.io/docs/api-endpoints in recent days,
and I found a strange thing is that when Atlantis was trying to construct the PullRequest model,
BaseBranch
,HeadBranch
,HeadCommit
in the PullRequest model were the same valuerequest.Ref
, and the source code is here https://github.com/runatlantis/atlantis/blob/v0.29.0/server/controllers/api_controller.go#L248-L250code capture:
this logic leads to an issue for me, after running a plan through API on a target project, the dir created by the plan will be overridden by the apply API call due to the reason
{"level":"debug","ts":"2024-11-15T19:01:16.817+0800","caller":"events/working_dir.go:136","msg":"repo was already cloned but is not at correct commit, wanted 'atlantis-api-test' got '6f3b9277ec240d6b6f9521a76caf5374316a1eaf'","json":{}}
, source code is here https://github.com/runatlantis/atlantis/blob/main/server/events/working_dir.go#L128-L137 , then Atlantis will do a force clone, this action will clean up the tf status files created by the previous plan, so the apply call always fails due to the errorError running apply operation: no plan found at path \"infra/glue/wap/wap-udp-dev\" and workspace \"default\"–did you run plan?
And I see if the plan is triggered by events(gitops way), it can correctly get the PR details through the below logic
https://github.com/runatlantis/atlantis/blob/v0.29.0/server/events/event_parser.go#L609-L618
Anyone can help me understand the above logic? thanks!
Reproduction Steps
plan API request:
apply API request:
Logs
Environment details
server --checkout-strategy=merge
Atlantis server-side config file:
Repo
atlantis.yaml
file:Additional Context
The text was updated successfully, but these errors were encountered: