Closed josemalonsom closed 7 years ago
Hello! I had the same problem recently. The solution is very easy.
First of all, remove gitlabCommitStatus(name: 'jenkins')
from options
, then add this anywhere after the top pipeline
declaration
post {
failure {
updateGitlabCommitStatus name: 'build', state: 'failed'
}
success {
updateGitlabCommitStatus name: 'build', state: 'success'
}
}
This will mark your commits accordingly. Hope this helps!
@mstg it works! Thank you very much.
But, before I close the issue: it is supposed to work like that or it's a bug?, the status is set when the job is done so I would expect that the status were set accordingly.
@josemalonsom I think it may be a bug. As it is supposed to update with the correct status (Ref)
If you have several steps for build etc., it just marked as passed immediately for me, but using post
and updateGitlabCommitStatus
works.
@mstg Ok. I'll use your workaround, it is very helpful, but I'll keep the issue open. Thank you :)
I'm not using Declarative yet so I'm not sure whether this is a bug or not. @colourmeamused since you added the Declarative support, can you take a look at this issue and let us know what the expected workflow is?
@mstg This does indeed partly fix the issue, but doing this disables the ability to see statuses like pending, building etc. which is (I believe) enabled by having the gitlabCommitStatus(name: 'jenkins')
in options
.
Having both of them (in options
and post
) makes it add multiple build statuses to Gitlab, so that sadly doesn't fix that.
Verified that this is a problem for me as well. Having it in options
like the readme will always return success
even when job `failed.
I am using @mstg suggestion.
However to have the pending
status, i modified it to have this in the first step of my build
stage. This would show pending on gitlab
. This might work for you as well @broodzak
updateGitlabCommitStatus name: 'jenkins', state: 'pending'
@colourmeamused ping?
@mstg This does indeed partly fix the issue, but doing this disables the ability to see statuses like pending, building etc. which is (I believe) enabled by having the gitlabCommitStatus(name: 'jenkins') in options.
Yup, I don't have access to the code I used when I updated the README, but I was using a similar workaround.
I had the same line in options
to set statuses like pending, building etc. in GitLab.
gitlabCommitStatus(name: 'jenkins')
And then I explicitly set the status for each stage in a post block within the stage:
post { failure { updateGitlabCommitStatus name: '<stagename>', state: 'failed' } success { updateGitlabCommitStatus name: '<stagename>', state: 'success' } }
Verbose and ugly but it works. We don't explicitly set status for the job, just use options
to give it the label jenkins.
So the GitLab page looks something like this: https://about.gitlab.com/images/8_11/pipelines_mr.png GitLab shows live status of each stage as it builds.
I can dig up my code test it and update the example in the README with screenshots unless there's a better workaround?
@colourmeamused cool, I get it now. If you can verify and update the README when you have a chance, that would be awesome. Thank you!
Hello,
Just to be sure that I understood it well, using gitlabCommitStatus(name: 'jenkins')
in options
will not automatically trigger success or failed state?
Do we need to manually add updateGitlabCommitStatus
for success and failure in post hooks in each of our declarative pipeline?
I think it's a bug. Debugging you can see that Jenkins is reporting the build as failed but the plugin is setting the build state as success.
The screenshot is from this line of code https://github.com/jenkinsci/gitlab-plugin/blob/fee5f715ccd5e0e611411cb83dfd0cd838409029/src/main/java/com/dabsquared/gitlabjenkins/util/CommitStatusUpdater.java#L35 and the problem occurs here https://github.com/jenkinsci/gitlab-plugin/blob/fee5f715ccd5e0e611411cb83dfd0cd838409029/src/main/java/com/dabsquared/gitlabjenkins/workflow/GitLabCommitStatusStep.java#L73.
It seems that the method BodyExecutionCallback.onSuccess() is called always that the body has completed successfully, but that only means that no exception was thrown and the build result can be any and it should be checked in order to set the commit status but the code assumes that it's always success
Looks like my #555 is a duplicate of this. I have a workaround there for getting the pending/running/etc status on a per-stage basis. Put gitlabBuilds()
in the options{}
to pre-announce all your stages, then use gitlabCommitStatus()
in all of those stages. Be careful to add post{}
sections to conditionally executed stages to close out the status for them.
@omehegan can you take a look at my comment?
I think that it's a bug and labeling it as doc improvement
(as in https://github.com/jenkinsci/gitlab-plugin/issues/555) can be hiding the real problem.
@josemalonsom I'm not sure your analysis is correct. I think when a Jenkins job first starts, the value of BallColor is inherited from the previous job run. That's why when build 1 fails, and then the job runs a second time, its icon in the UI is still red unless and until it completes successfully. That may be what you are seeing when you trace the execution there. And I think what @jgeorgeson is calling a workaround is just how this was designed to work. I'm still not sure there's any other issue here.
@omehegan I checked it again and if I don’t missing something the result of the screenshot is the actual result of the step execution, it changes in every execution with the expected status of the step, it doesn't show the status of previous executions, the BallColor is a value of the step execution result, you can see it here hudson.model.Result.
Anyway, I can’t reproduce the error anymore because right now it’s working as expected, a failure is updated in Gitlab as a failure. I think that it was some other Jenkins’s plugin that had the problem and in some version it was fixed somehow, I can see debugging that now onSuccess is not called anymore when the step fails. Because Jenkins always installs the newest versions in a clean install I can’t figure out which plugin may have been, maybe one related to the declarative pipeline.
Maybe other person with the same problem can confirm that it’s solved when the plugins are updated, ¿@mstg, @Zaccc123, ...?
Duplicated by #555.
Issue
The plugin always show success in Gitlab even when the job has failed.
Jenkinsfile:
Context
Logs & Traces
Jenkins job output:
Gitlab plugin log:
Problem description
I have a pipeline with the declarative syntax and I expect that the plugin updates the status in Gitlab accordingly when the build fails but it always sets the status to success.
It seems to be related to https://github.com/jenkinsci/gitlab-plugin/issues/501.