Add functionality to add the new publisher automatically to old jobs if addCiMessage was activated for the GitLabPushTrigger

This commit is contained in:
Robin Müller 2016-02-13 00:17:47 +01:00
parent d6bb94b833
commit c457e13d6a
3 changed files with 42 additions and 2 deletions

View File

@ -85,6 +85,7 @@ public class GitLabPushTrigger extends Trigger<Job<?, ?>> {
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<Job<?, ?>> {
@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<Job<?, ?>> {
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<Job<?, ?>> {
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;
}

View File

@ -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<Publisher> {
private boolean migrationFinished = false;
@Override
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
return true;

View File

@ -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);