-
Notifications
You must be signed in to change notification settings - Fork 619
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
Adds a Modern Mode handling for merge requests. #285
Conversation
…lugin will fetch Merge Requests from origin instead of using parameterized builds.
Here's the original comment I wrote on #252: This PR enhances gitlab-plugin by adding two operation modes: Modern and Legacy. Modern works with GitLab 8.1 or better, and provides an easier configuration of projects in Jenkins (a single Git repository is enough) and much better handling of Merge Requests (MR are fetched from origin and matched by SHA1 instead of comparing branch names). |
@pbendersky thanks a lot for doing this work! |
@@ -5,6 +5,7 @@ | |||
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabApi; | |||
import com.dabsquared.gitlabjenkins.gitlab.api.model.BuildState; | |||
import hudson.EnvVars; | |||
import hudson.model.AbstractBuild; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you using AbstractBuild here? Note that, in order to support Pipeline jobs, AbstractJob and AbstractBuild can't be used. See https://github.com/jenkinsci/pipeline-plugin/blob/master/DEVGUIDE.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not. I'll add a commit removing it.
@coder-hugo @omehegan I'm keeping this PR updated with master, so it's easier to merge when you want to. |
@pbendersky thanks! I'm going to try to test it in my environment tomorrow, where we use GitLab CE 7.14. That's probably the most I can do with it. @coder-hugo said that he will look through it as soon as he can. |
# Conflicts: # src/main/java/com/dabsquared/gitlabjenkins/cause/CauseData.java # src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerLegacyImpl.java
…ild was initiated manually instead of through a GitLab trigger.
@pbendersky I'm working on testing this. The only merge conflict is with changes to the README, so it should be easy to resolve that. |
Nice! Let me know if you need anything, or you have comments on the code. |
@pbendersky there seems to be a bug in the existing HEAD of master, I'm getting an NPE when I trigger a build with that code. Unrelated to your change. I'll see if I can track it down. |
Is there any update on the status of this PR? Or on the next release (1.2.3) in general? There are some fixes in master that would be good to have released. |
I determined yesterday that the current master has a bug that breaks compatibility with GitLab 7.14 and possibly everything before GitLab 8.5. I have a patch for it that just needs cleanup. I will merge that this week and then I can test this change. |
OK, I have successfully tested this with GitLab 7.14, using the legacy mode, and it correctly triggers a build based on push or MR, and checks out the right branch. So that much looks good to me. |
public enum GitLabPluginMode { | ||
LEGACY, | ||
MODERN; | ||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to keep all this commented out stuff?
I posted some minor comments on the code. Also wanted to note that I tested with a Pipeline job and it works; this should imply that it will work with Freestyle jobs as well. @coder-hugo pending comments from you before we merge this. I've reviewed as much as I think I can. |
- Addressed comments in PR
@omehegan Just fixed these minor issues, and merged from upstream, to make things easier. |
@@ -21,7 +21,11 @@ | |||
- [Parameterized builds](#parameterized-builds) | |||
- [Branch filtering](#branch-filtering) | |||
- [Build Tags](#build-tags) | |||
<<<<<<< HEAD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you committed the merge conflicts of README...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just added a new commit fixing it.
@coder-hugo ping |
List<PushHookTriggerHandler> result = new ArrayList<PushHookTriggerHandler>(); | ||
if (triggerOnPush) { | ||
result.add(new PushHookTriggerHandlerImpl()); | ||
} | ||
if (triggerOpenMergeRequestOnPush == TriggerOpenMergeRequest.both) { | ||
if (gitLabPluginMode == GitLabPluginMode.LEGACY && triggerOpenMergeRequestOnPush == TriggerOpenMergeRequest.both) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this you disable the functionality to rebuild open MRs if the target branch has changed for the modern mode. Why you are doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because that case is handled by the Merge Request hook instead (if a MR is created and a commit added, the MR hook is called again).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. I just tested this with GitLab 8.7:
- I configured the job in Jenkins as you described in the README
- I configured my GitLab repo to send MR events to the Jenkins
- I created a MR for a test branch into the master -> a new build was triggerd
- I pushed some changes to the master (target branch) -> no build was triggered as no event was sent by GitLab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. The case I was referring was new commits on the source branch (the user's fork). That gets handled by the MR trigger. I'll take a look at this, it might be a limitation of the "Modern" approach (if that's the case, I'll document it to reflect it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coder-hugo just looked a bit at this... seems to be a limitation of the Modern mode. Since the user only has one repo configured, a new commit to master
in the target branch can't be merged to the MR by Jenkins.
I suggest:
- Updating the Readme to reflect this.
- Ideally (I'll check how can it be done) change the drop down when selecting Modern mode, so the user can only select "Source branch" on when to re-build.
Thoughts?
…ing open MR when pushing to source branch. - Changed the settings so when switching the plugin Mode the options for "triggerOpenMergeRequest" are refreshed and show only the possible values.
@coder-hugo just added a two commits:
I also merged the latest changes from master, so it passes the checks here. |
@pbendersky it looks like you have interchanged the meaning of source and target branch of a MR. The source branch is the one that contains the changes that shall be merged to the target branch. So the modern mode supports re-building open MRs by pushes to the source but not to the target branch. And as the target branch is part of the configured repository it should be possible to re-build open MRs also for pushes to the target branch. |
Oh... I'll revert the source / target then. So, a better approach (that would cover all the cases) would be to instead of fetching from |
@coder-hugo I see one problem, however. Let's say there are 3 merge requests open, and a user commits to |
@pbendersky I don't see any problem there. You would like to know if the master is still stable but also if the source branches can be safely merged to the target branch. |
@omorillo @coder-hugo I'm trying to wrap this up... Pending tasks (as discussed):
Now I need some help, and maybe you can give me a pointer... We currently create a |
@pbendersky you don't need to add a special |
@coder-hugo right, but it loses some of the charm. As it is now, you simply set up |
@pbendersky you can try to extend the |
# Conflicts: # README.md # src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java # src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerFactory.java # src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerLegacyImpl.java # src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/push/PushHookTriggerHandlerFactory.java # src/main/java/com/dabsquared/gitlabjenkins/util/CommitStatusUpdater.java # src/test/java/com/dabsquared/gitlabjenkins/publisher/GitLabCommitStatusPublisherTest.java # src/test/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerImplTest.java
@coder-hugo @omehegan please take a look at #370. While I'm not giving up on this PR (I still think the setup with a single repository is easier to manage), the minor changes in configuration explained in #370 achieve the same result. |
Hello, any news with this Pull Request? I am interested because #98 |
I think it's a dead end at this point... With the configuration now in the README, I don't think this is needed. Did you try that? |
Should we make a call on this one? It sounds like we should close it. Agreed? |
Agreed. |
Merge in latest from jenkinsci
Merge pull request jenkinsci#285 from jenkinsci/master
In Modern Mode, the plugin will fetch Merge Requests from origin instead of using parameterized builds.
This supersedes #252 and works with the refactored 1.2 codebase.