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

Atlantis - Gitlab integration failing when updating MR with new commits on version v0.29.0 #4950

Closed
joaoluchetti opened this issue Sep 25, 2024 · 5 comments · Fixed by #5033
Labels
bug Something isn't working provider/gitlab

Comments

@joaoluchetti
Copy link

Hi All,

After updating to atlantis v0.29.0 we are having issues when updating Gitlab Merge Requests with new commits.

When the MR is opened the atlantis pipeline runs without any issue, although when we add another commit to the MR the status of pipeline is stuck on "Checking pipeline status", the atlantis plan and apply run without any issues but we can't merge the MR as the pipeline is not identified as succeded.

Looking at the logs we found the following exception:

2024-09-25 14:17:19.087 {"level":"error","ts":"2024-09-25T17:17:19.087Z","caller":"events/project_command_runner.go:195","msg":"updating project PR status%!(EXTRA *errors.errorString=404 Not Found)","json":{"repo":"myorg/myrepo","pull":"133"},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*ProjectOutputWrapper).updateProjectPRStatus\n\tgit.luolix.top/runatlantis/atlantis/server/events/project_command_runner.go:195\ngit.luolix.top/runatlantis/atlantis/server/events.(*ProjectOutputWrapper).Plan\n\tgit.luolix.top/runatlantis/atlantis/server/events/project_command_runner.go:164\ngit.luolix.top/runatlantis/atlantis/server/events.RunAndEmitStats\n\tgit.luolix.top/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:74\ngit.luolix.top/runatlantis/atlantis/server/events.(*InstrumentedProjectCommandRunner).Plan\n\tgit.luolix.top/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:38\ngit.luolix.top/runatlantis/atlantis/server/events.runProjectCmds\n\tgit.luolix.top/runatlantis/atlantis/server/events/project_command_pool_executor.go:48\ngit.luolix.top/runatlantis/atlantis/server/events.(*PlanCommandRunner).runAutoplan\n\tgit.luolix.top/runatlantis/atlantis/server/events/plan_command_runner.go:136\ngit.luolix.top/runatlantis/atlantis/server/events.(*PlanCommandRunner).Run\n\tgit.luolix.top/runatlantis/atlantis/server/events/plan_command_runner.go:305\ngit.luolix.top/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunAutoplanCommand\n\tgit.luolix.top/runatlantis/atlantis/server/events/command_runner.go:223"}

We can confirm that this behavior does not happen on version v0.28.x.

@joaoluchetti joaoluchetti added the bug Something isn't working label Sep 25, 2024
Copy link

dosubot bot commented Sep 25, 2024

@joaoluchetti Hello there! I'm here to assist you with any bugs, questions, or contributions while we wait for a human maintainer.

The issue you're encountering with the Atlantis Gitlab integration on version v0.29.0, where the pipeline status is stuck on "Checking pipeline status" after adding new commits to a Merge Request, is likely due to the GetAtlantisStatus function expecting exactly one pipeline to be associated with a Merge Request. If there are multiple pipelines, it returns an error, causing the status to remain in a checking state.

Here's the relevant part of the code:

func (g GitlabClient) GetAtlantisStatus(ctx context.Context, branchName string) (string, error) {
    pipelineInfos, _, err := g.client.MergeRequests.ListMergeRequestPipelines(g.projectId, g.branchToMR[branchName])
    if (err != nil) {
        return "", err
    }
    if len(pipelineInfos) != 1 {
        return "", fmt.Errorf("unexpected pipelines: %d", len(pipelineInfos))
    }
    pipelineInfo := pipelineInfos[0]
    pipeline, _, err := g.client.Pipelines.GetPipeline(g.projectId, pipelineInfo.ID)
    if err != nil) {
        return "", err
    }

    return pipeline.Status, nil
}

Additionally, the updateProjectPRStatus function in project_command_runner.go handles errors by setting the commit status to FailedCommitStatus if there is an error or failure in the result of the executed command. A 404 Not Found error specifically occurs when the directory does not exist, indicated by the DirNotExistErr error type.

Here is the relevant code:

func (p *ProjectOutputWrapper) updateProjectPRStatus(commandName command.Name, ctx command.ProjectContext, execute func(ctx command.ProjectContext) command.ProjectResult) command.ProjectResult {
    if err := p.JobURLSetter.SetJobURLWithStatus(ctx, commandName, models.PendingCommitStatus, nil); err != nil {
        ctx.Log.Err("updating project PR status", err)
    }

    result := execute(ctx)

    if result.Error != nil || result.Failure != "" {
        if err := p.JobURLSetter.SetJobURLWithStatus(ctx, commandName, models.FailedCommitStatus, &result); err != nil {
            ctx.Log.Err("updating project PR status", err)
        }

        return result
    }

    if err := p.JobURLSetter.SetJobURLWithStatus(ctx, commandName, models.SuccessCommitStatus, &result); err != nil {
        ctx.Log.Err("updating project PR status", err)
    }

    return result
}

The DirNotExistErr error type:

type DirNotExistErr struct {
    RepoRelDir string
}

func (d DirNotExistErr) Error() string {
    return fmt.Sprintf("dir %q does not exist", d.RepoRelDir)
}

For more details, you can refer to the related issue here [1][2][3].

To continue talking to Dosu, mention @dosu.

@eduardohermannarquivei
Copy link

+1

@KelvinVenancio
Copy link

same here with the v0.29.0 version!

@brontolinux
Copy link

I just wanted to chime in and say that the problem is still present in v0.30.0. The error I had was

{"level":"warn","ts":"2024-10-03T12:44:17.887Z","caller":"events/pre_workflow_hooks_command_runner.go:144","msg":"unable to update pre workflow hook status: 404 Not Found","json":{"repo":"myorg/myrepo","pull":"519"},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*DefaultPreWorkflowHooksCommandRunner).runHooks\n\tgit.luolix.top/runatlantis/atlantis/server/events/pre_workflow_hooks_command_runner.go:144\ngit.luolix.top/runatlantis/atlantis/server/events.(*DefaultPreWorkflowHooksCommandRunner).RunPreHooks\n\tgit.luolix.top/runatlantis/atlantis/server/events/pre_workflow_hooks_command_runner.go:84\ngit.luolix.top/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\tgit.luolix.top/runatlantis/atlantis/server/events/command_runner.go:361"}

...and then of course several others while also trying to make the thing work again. 0.28.5 works fine.

@aimbot31
Copy link

can reproduce

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
5 participants