Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitlab: Atlantis apply returns Status cannot transition via \"run\" when updating commit check status #2685

Open
fazith27 opened this issue Nov 14, 2022 · 8 comments
Labels
bug Something isn't working provider/gitlab

Comments

@fazith27
Copy link

fazith27 commented Nov 14, 2022

Community Note

  • 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

I started exploring Atlantis recently. I found an issue when running atlantis apply. Pipeline at Gitlab end is continuously running even after applying the changes and the MR is updated with the apply successful comment. Provided atlantis logs below for reference. As per the logs, it looks like Atlantis is failing when making the Gitlab api to update the commit status and the process never ends in the backend. FYI, I am using Gitlab and Terragrunt.

Reproduction Steps

  • docker run -p 80:4141 -d --pull=always registry.gitlab.com/mytestproj/tf-stack/custom-atlantis server --gitlab-user=xxxxx --gitlab-token=xxxxx --repo-allowlist=gitlab.com/mytestproj/tf-stack --gitlab-webhook-secret=xxxx--repo-config="/home/atlantis/repos.yaml" --silence-no-projects --checkout-strategy=merge
  • Added webhook at Gitlab end to post the MR events to atlantis
  • Created MR in Gitlab
  • Commented atlantis plan and then atlantis apply 3 to 4 times in the same MR with multiple changes
  • First apply ran successfully and after that the apply pipeline never ends in Gitlab

Logs

{
  "level":"warn","ts":"2022-11-14T22:18:33.360Z",
  "caller":"events/apply_command_runner.go:204",
  "msg":"unable to update commit status: POST https://gitlab.com/api/v4/projects/mytestproj/tf-stack/statuses/8b9c4d85c3ed817d7222093412dfa37dc612d81c: 400 {message: Cannot transition status via :run from :running (Reason(s): Status cannot transition via \"run\")}",
  "json":{"repo":"mytestproj/tf-stack","pull":"7"},
  "stacktrace":"github.com/runatlantis/atlantis/server/events.(*ApplyCommandRunner).updateCommitStatus\n\tgithub.jparrowsec.cn/runatlantis/atlantis/server/events/apply_command_runner.go:204\ngithub.jparrowsec.cn/runatlantis/atlantis/server/events.(*ApplyCommandRunner).Run\n\tgithub.jparrowsec.cn/runatlantis/atlantis/server/events/apply_command_runner.go:163\ngithub.jparrowsec.cn/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\tgithub.jparrowsec.cn/runatlantis/atlantis/server/events/command_runner.go:296"
}

Dockerfile for my custom image

FROM ghcr.io/runatlantis/atlantis
RUN curl --output terragrunt -L https://github.com/gruntwork-io/terragrunt/releases/download/v0.40.1/terragrunt_linux_amd64 && chmod +x terragrunt && mv terragrunt /usr/local/bin/terragrunt
COPY repos.yaml /home/atlantis

Server side-config (repos.yaml)

repos:
- id: "/.*/"
  # apply_requirements: [approved]
  allowed_overrides: [workflow]
  allow_custom_workflows: true
  workflow: terragrunt
  pre_workflow_hooks:
    - run: chmod +x gen-atlantis-yaml.sh && ./gen-atlantis-yaml.sh
  post_workflow_hooks:
    - run: find . -type d -name ".terragrunt-cache" -prune -exec rm -rf {} \;
workflows:
  terragrunt:
    plan:
      steps:
      - env:
          name: TERRAGRUNT_TFPATH
          command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
      - run: terragrunt plan -input=false -out=$PLANFILE
      - run: terragrunt show -json $PLANFILE > $SHOWFILE
    apply:
      steps:
      - env:
          name: TERRAGRUNT_TFPATH
          command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
      - run: terragrunt apply -input=false $PLANFILE

Atlantis yaml

version: 3
parallel_apply: false
parallel_plan: true
automerge: false
workflows:
  terragrunt:
    plan:
      steps:
      - env:
          name: TERRAGRUNT_TFPATH
          command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
      - run: terragrunt plan -out $PLANFILE
    apply:
      steps:
      - env:
          name: TERRAGRUNT_TFPATH
          command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
      - run: terragrunt apply $PLANFILE
projects:
- dir: env/np/lb
  workflow: terragrunt
- dir: env/p/lb
  workflow: terragrunt
- dir: env/s/lb
  workflow: terragrunt
@fazith27 fazith27 added the bug Something isn't working label Nov 14, 2022
@nitrocode
Copy link
Member

@fazith27 what atlantis version are you using?

@fazith27
Copy link
Author

I am using atlantis 0.19.8. I think I figured out when the issue happens. It is happening when we are doing the targeted apply. I just ran atlantis plan which ran plan for three of my projects but only one project actually had a change. So I ran targeted apply atlantis apply -d <path_to_project>. The apply is successfull as I could see the MR is updated with apply output but the Gitlab pipline is not ended. It shows still running with the same error I posted above.

@nitrocode nitrocode changed the title Atlantis apply running continously even after applied the changes gitlab: Atlantis apply running continously even after applied the changes Nov 14, 2022
@nitrocode
Copy link
Member

nitrocode commented Nov 14, 2022

It seems like a gitlab specific issue. I'm unsure if they changed their API or if this is an edge case that no one accounted for.

Seems like the API is throwing the error and it's falling into the error block here.

if err := a.commitStatusUpdater.UpdateCombinedCount(
ctx.Pull.BaseRepo,
ctx.Pull,
status,
command.Apply,
numSuccess,
len(pullStatus.Projects),
); err != nil {
ctx.Log.Warn("unable to update commit status: %s", err)
}

func (d *DefaultCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName command.Name, numSuccess int, numTotal int) error {

func (g *GitlabClient) UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) error {

PRs are welcome if you or someone can troubleshoot this.

@nitrocode nitrocode changed the title gitlab: Atlantis apply running continously even after applied the changes gitlab: Atlantis apply returns Status cannot transition via \"run\" when updating commit check status Dec 22, 2022
@Brightside56
Copy link

Have similar/same issue and it's very annoying

{"level":"warn","ts":"2024-01-25T18:24:21.242Z","caller":"events/plan_command_runner.go:191","msg":"unable to update commit status: POST https://somegitlab.com/api/v4/projects/xxx/yyy/statuses/1d513a0d019425c7116e42507e35d11670e4f42e: 400 {message: Cannot transition status via :run from :running (Reason(s): Status cannot transition via \"run\")}","json":{"repo":"xxx/yyy","pull":"304"},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*PlanCommandRunner).run\n\tgithub.jparrowsec.cn/runatlantis/atlantis/server/events/plan_command_runner.go:191\ngithub.jparrowsec.cn/runatlantis/atlantis/server/events.(*PlanCommandRunner).Run\n\tgithub.jparrowsec.cn/runatlantis/atlantis/server/events/plan_command_runner.go:306\ngithub.jparrowsec.cn/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\tgithub.jparrowsec.cn/runatlantis/atlantis/server/events/command_runner.go:365"}

@tweiss-mdm
Copy link

tweiss-mdm commented Mar 7, 2024

Encountering same issue on Atlantis 0.27.1 and Gitlab 16.8

caller":"events/apply_command_runner.go:221","msg":"unable to update commit status: POST

@elft3r
Copy link
Contributor

elft3r commented Mar 27, 2024

Hey,
I started looking into this issue by debugging the code. It seems like this warning is a symptom of another problem. My current understanding is that this error is retrieved when you set the pipeline status to running when it is already in the state running.

My next step is to figure out why it's not transitioning to either success or failed. I will keep you posted on what I learned.

@rjmsilveira
Copy link

Hi all. Just adding to this that I started seeing error Cannot transition status via :run from :running when I closed an MR, and reopened it.
Not sure if this helps but before that everything was working fine.
Plans still work but pipelines are no longer created (or updated)

@AntonioAlfrz
Copy link

Hello, has there been any progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working provider/gitlab
Projects
None yet
Development

No branches or pull requests

7 participants