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

Open
joaoluchetti opened this issue Sep 25, 2024 · 3 comments
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\tgithub.com/runatlantis/atlantis/server/events/project_command_runner.go:195\ngithub.com/runatlantis/atlantis/server/events.(*ProjectOutputWrapper).Plan\n\tgithub.com/runatlantis/atlantis/server/events/project_command_runner.go:164\ngithub.com/runatlantis/atlantis/server/events.RunAndEmitStats\n\tgithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:74\ngithub.com/runatlantis/atlantis/server/events.(*InstrumentedProjectCommandRunner).Plan\n\tgithub.com/runatlantis/atlantis/server/events/instrumented_project_command_runner.go:38\ngithub.com/runatlantis/atlantis/server/events.runProjectCmds\n\tgithub.com/runatlantis/atlantis/server/events/project_command_pool_executor.go:48\ngithub.com/runatlantis/atlantis/server/events.(*PlanCommandRunner).runAutoplan\n\tgithub.com/runatlantis/atlantis/server/events/plan_command_runner.go:136\ngithub.com/runatlantis/atlantis/server/events.(*PlanCommandRunner).Run\n\tgithub.com/runatlantis/atlantis/server/events/plan_command_runner.go:305\ngithub.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunAutoplanCommand\n\tgithub.com/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!

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

3 participants