jenkinsci / gitlab-plugin

A Jenkins plugin for interfacing with GitLab
https://plugins.jenkins.io/gitlab-plugin/
GNU General Public License v2.0
1.43k stars 613 forks source link

Jenkins queue action added that mimics logic in PendingBuildsHandler to avoid pending pipelines for jobs dropped from the queue. #1681

Closed sebhopley closed 2 weeks ago

sebhopley commented 4 weeks ago

This change fixes a bug where pipelines are left stuck at pending in Gitlab.

The issue is that builds with a different source branch but the same commit are not treated as a duplicate by the PendingBuildsHandler (which is correct). The builds get scheduled but the Jenkins queue manager only checks if the commits are the same not the source branch as such it sees the build as a duplicate and removes it from the queue, because the job is never run the pipeline status is never updated and it sits at pending until manually cancelled.

This was fixed by adding a queue action for the queue manger to use to determine if the builds have the same source branch or not.

Testing done

I've added tests for the scenario.

Submitter checklist

krisstern commented 3 weeks ago

Hi @sebhopley, Thanks for your contribution! I will review the PR over the next fews days and get back to you shortly

sebhopley commented 2 weeks ago

Hi please let me know if you need any more details. For us we have a process that merges change from our main trunk branch back into any feature branches by opening a merge request with a source branch taken of the main trunk (so conflicts can be resolved in the gitlab ui) this basically means you have effectively 5-10 builds all run at the same time that are the same commit but a different branch name.

krisstern commented 2 weeks ago

Hi @sebhopley, Actually I have some problem installing the hpi file I derived from your PR to test it further, as I am seeing the stack trace:

java.io.IOException: Failed to load: GitLab Plugin (gitlab-plugin 1.9.1-SNAPSHOT (private-f532502f-krisstern))
 - Jenkins (2.472) or higher required
    at hudson.PluginWrapper.resolvePluginDependencies(PluginWrapper.java:992)
    at hudson.PluginManager.dynamicLoad(PluginManager.java:952)
Caused: java.io.IOException: Failed to install gitlab-plugin plugin
    at hudson.PluginManager.dynamicLoad(PluginManager.java:966)
    at hudson.model.UpdateCenter$InstallationJob._run(UpdateCenter.java:2249)
Caused: java.io.IOException: Failed to dynamically deploy this plugin
    at hudson.model.UpdateCenter$InstallationJob._run(UpdateCenter.java:2253)
    at hudson.model.UpdateCenter$DownloadJob.run(UpdateCenter.java:1899)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at hudson.remoting.AtmostOneThreadExecutor$Worker.run(AtmostOneThreadExecutor.java:121)
    at java.base/java.lang.Thread.run(Thread.java:1583)
krisstern commented 2 weeks ago

I think it could be my local setup... Let me fix this and test first