Skip to content

Commit

Permalink
Add functionality to add the new publisher automatically to old jobs …
Browse files Browse the repository at this point in the history
…if addCiMessage was activated for the GitLabPushTrigger
  • Loading branch information
coder-hugo committed Feb 20, 2016
1 parent 7d5877b commit d9961be
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,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 final String branchFilterName;
private final String includeBranchesSpec;
Expand All @@ -93,7 +94,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;
Expand All @@ -102,6 +103,7 @@ public GitLabPushTrigger(boolean triggerOnPush, boolean triggerOnMergeRequest, S
this.ciSkip = ciSkip;
this.setBuildDescription = setBuildDescription;
this.addNoteOnMergeRequest = addNoteOnMergeRequest;
this.addCiMessage = addCiMessage;
this.addVoteOnMergeRequest = addVoteOnMergeRequest;
this.branchFilterName = branchFilterName;
this.includeBranchesSpec = includeBranchesSpec;
Expand Down Expand Up @@ -138,6 +140,22 @@ public boolean getAcceptMergeRequestOnSuccess() {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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;
Expand Down Expand Up @@ -112,9 +114,28 @@ private String retrieveProjectId(String remoteUrl) throws URISyntaxException {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ protected GitLabPushTrigger setUpWithPushTrigger() {
boolean ciSkip = false;
boolean setBuildDescription = true;
boolean addNoteOnMergeRequest = true;
boolean addCiMessage = true;
boolean addVoteOnMergeRequest = true;
boolean acceptMergeRequestOnSuccess = false;
String branchFilter = null;
String includeBranchesSpec = null;
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);

Expand Down

0 comments on commit d9961be

Please sign in to comment.