Skip to content

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

@fazith27

Description

@fazith27

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.com/runatlantis/atlantis/server/events/apply_command_runner.go:204\ngithub.com/runatlantis/atlantis/server/events.(*ApplyCommandRunner).Run\n\tgithub.com/runatlantis/atlantis/server/events/apply_command_runner.go:163\ngithub.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\tgithub.com/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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions