diff --git a/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java b/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java index 04f76c3..02626fd 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java @@ -85,6 +85,7 @@ public class GitLabPushTrigger extends Trigger> { private boolean ciSkip = true; private boolean setBuildDescription = true; private boolean addNoteOnMergeRequest = true; + private boolean addCiMessage = false; private boolean addVoteOnMergeRequest = true; private transient boolean allowAllBranches = false; private final String branchFilterName; @@ -96,7 +97,7 @@ public class GitLabPushTrigger extends Trigger> { @DataBoundConstructor public GitLabPushTrigger(boolean triggerOnPush, boolean triggerOnMergeRequest, String triggerOpenMergeRequestOnPush, - boolean ciSkip, boolean setBuildDescription, boolean addNoteOnMergeRequest, + boolean ciSkip, boolean setBuildDescription, boolean addNoteOnMergeRequest, boolean addCiMessage, boolean addVoteOnMergeRequest, boolean acceptMergeRequestOnSuccess, String branchFilterName, String includeBranchesSpec, String excludeBranchesSpec, String targetBranchRegex) { this.triggerOnPush = triggerOnPush; @@ -105,6 +106,7 @@ public class GitLabPushTrigger extends Trigger> { this.ciSkip = ciSkip; this.setBuildDescription = setBuildDescription; this.addNoteOnMergeRequest = addNoteOnMergeRequest; + this.addCiMessage = addCiMessage; this.addVoteOnMergeRequest = addVoteOnMergeRequest; this.branchFilterName = branchFilterName; this.includeBranchesSpec = includeBranchesSpec; @@ -141,6 +143,22 @@ public class GitLabPushTrigger extends Trigger> { return acceptMergeRequestOnSuccess; } + /** + * @deprecated see {@link com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher} + */ + @Deprecated + public boolean getAddCiMessage() { + return addCiMessage; + } + + /** + * @deprecated see {@link com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher} + */ + @Deprecated + public void setAddCiMessage(boolean addCiMessage) { + this.addCiMessage = addCiMessage; + } + public boolean getCiSkip() { return ciSkip; } diff --git a/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabCommitStatusPublisher.java b/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabCommitStatusPublisher.java index 648472b..b0c6baa 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabCommitStatusPublisher.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/publisher/GitLabCommitStatusPublisher.java @@ -3,6 +3,8 @@ package com.dabsquared.gitlabjenkins.publisher; import com.dabsquared.gitlabjenkins.GitLabPushTrigger; import hudson.Extension; import hudson.Launcher; +import hudson.init.InitMilestone; +import hudson.init.Initializer; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; import hudson.model.BuildListener; @@ -112,9 +114,28 @@ public class GitLabCommitStatusPublisher extends Notifier { return projectId; } + @Initializer(after = InitMilestone.JOB_LOADED) + public static void migrateJobs() throws IOException { + DescriptorImpl descriptor = (DescriptorImpl) Jenkins.getInstance().getDescriptor(GitLabCommitStatusPublisher.class); + if (!descriptor.migrationFinished) { + for (AbstractProject project : Jenkins.getInstance().getAllItems(AbstractProject.class)) { + GitLabPushTrigger trigger = project.getTrigger(GitLabPushTrigger.class); + if (trigger != null && trigger.getAddCiMessage()) { + project.getPublishersList().add(new GitLabCommitStatusPublisher()); + trigger.setAddCiMessage(false); + project.save(); + } + } + descriptor.migrationFinished = true; + descriptor.save(); + } + } + @Extension public static class DescriptorImpl extends BuildStepDescriptor { + private boolean migrationFinished = false; + @Override public boolean isApplicable(Class aClass) { return true; diff --git a/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java b/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java index e942def..bc31152 100644 --- a/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java +++ b/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java @@ -122,6 +122,7 @@ public abstract class AbstractGitLabPushTriggerGitlabServerTest { boolean ciSkip = false; boolean setBuildDescription = true; boolean addNoteOnMergeRequest = true; + boolean addCiMessage = true; boolean addVoteOnMergeRequest = true; boolean acceptMergeRequestOnSuccess = false; String branchFilter = null; @@ -129,7 +130,7 @@ public abstract class AbstractGitLabPushTriggerGitlabServerTest { String excludeBranchesSpec = null; String targetBranchRegex = null; GitLabPushTrigger gitLabPushTrigger = new GitLabPushTrigger(triggerOnPush, triggerOnMergeRequest, - triggerOpenMergeRequestOnPush, ciSkip, setBuildDescription, addNoteOnMergeRequest, + triggerOpenMergeRequestOnPush, ciSkip, setBuildDescription, addNoteOnMergeRequest, addCiMessage, addVoteOnMergeRequest, acceptMergeRequestOnSuccess, branchFilter, includeBranchesSpec, excludeBranchesSpec, targetBranchRegex);