Add functionality to add the new publisher automatically to old jobs if addCiMessage was activated for the GitLabPushTrigger
This commit is contained in:
parent
d6bb94b833
commit
c457e13d6a
|
@ -85,6 +85,7 @@ public class GitLabPushTrigger extends Trigger<Job<?, ?>> {
|
||||||
private boolean ciSkip = true;
|
private boolean ciSkip = true;
|
||||||
private boolean setBuildDescription = true;
|
private boolean setBuildDescription = true;
|
||||||
private boolean addNoteOnMergeRequest = true;
|
private boolean addNoteOnMergeRequest = true;
|
||||||
|
private boolean addCiMessage = false;
|
||||||
private boolean addVoteOnMergeRequest = true;
|
private boolean addVoteOnMergeRequest = true;
|
||||||
private transient boolean allowAllBranches = false;
|
private transient boolean allowAllBranches = false;
|
||||||
private final String branchFilterName;
|
private final String branchFilterName;
|
||||||
|
@ -96,7 +97,7 @@ public class GitLabPushTrigger extends Trigger<Job<?, ?>> {
|
||||||
|
|
||||||
@DataBoundConstructor
|
@DataBoundConstructor
|
||||||
public GitLabPushTrigger(boolean triggerOnPush, boolean triggerOnMergeRequest, String triggerOpenMergeRequestOnPush,
|
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,
|
boolean addVoteOnMergeRequest, boolean acceptMergeRequestOnSuccess, String branchFilterName,
|
||||||
String includeBranchesSpec, String excludeBranchesSpec, String targetBranchRegex) {
|
String includeBranchesSpec, String excludeBranchesSpec, String targetBranchRegex) {
|
||||||
this.triggerOnPush = triggerOnPush;
|
this.triggerOnPush = triggerOnPush;
|
||||||
|
@ -105,6 +106,7 @@ public class GitLabPushTrigger extends Trigger<Job<?, ?>> {
|
||||||
this.ciSkip = ciSkip;
|
this.ciSkip = ciSkip;
|
||||||
this.setBuildDescription = setBuildDescription;
|
this.setBuildDescription = setBuildDescription;
|
||||||
this.addNoteOnMergeRequest = addNoteOnMergeRequest;
|
this.addNoteOnMergeRequest = addNoteOnMergeRequest;
|
||||||
|
this.addCiMessage = addCiMessage;
|
||||||
this.addVoteOnMergeRequest = addVoteOnMergeRequest;
|
this.addVoteOnMergeRequest = addVoteOnMergeRequest;
|
||||||
this.branchFilterName = branchFilterName;
|
this.branchFilterName = branchFilterName;
|
||||||
this.includeBranchesSpec = includeBranchesSpec;
|
this.includeBranchesSpec = includeBranchesSpec;
|
||||||
|
@ -141,6 +143,22 @@ public class GitLabPushTrigger extends Trigger<Job<?, ?>> {
|
||||||
return acceptMergeRequestOnSuccess;
|
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() {
|
public boolean getCiSkip() {
|
||||||
return ciSkip;
|
return ciSkip;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package com.dabsquared.gitlabjenkins.publisher;
|
||||||
import com.dabsquared.gitlabjenkins.GitLabPushTrigger;
|
import com.dabsquared.gitlabjenkins.GitLabPushTrigger;
|
||||||
import hudson.Extension;
|
import hudson.Extension;
|
||||||
import hudson.Launcher;
|
import hudson.Launcher;
|
||||||
|
import hudson.init.InitMilestone;
|
||||||
|
import hudson.init.Initializer;
|
||||||
import hudson.model.AbstractBuild;
|
import hudson.model.AbstractBuild;
|
||||||
import hudson.model.AbstractProject;
|
import hudson.model.AbstractProject;
|
||||||
import hudson.model.BuildListener;
|
import hudson.model.BuildListener;
|
||||||
|
@ -112,9 +114,28 @@ public class GitLabCommitStatusPublisher extends Notifier {
|
||||||
return projectId;
|
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
|
@Extension
|
||||||
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
|
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
|
||||||
|
|
||||||
|
private boolean migrationFinished = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
|
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -122,6 +122,7 @@ public abstract class AbstractGitLabPushTriggerGitlabServerTest {
|
||||||
boolean ciSkip = false;
|
boolean ciSkip = false;
|
||||||
boolean setBuildDescription = true;
|
boolean setBuildDescription = true;
|
||||||
boolean addNoteOnMergeRequest = true;
|
boolean addNoteOnMergeRequest = true;
|
||||||
|
boolean addCiMessage = true;
|
||||||
boolean addVoteOnMergeRequest = true;
|
boolean addVoteOnMergeRequest = true;
|
||||||
boolean acceptMergeRequestOnSuccess = false;
|
boolean acceptMergeRequestOnSuccess = false;
|
||||||
String branchFilter = null;
|
String branchFilter = null;
|
||||||
|
@ -129,7 +130,7 @@ public abstract class AbstractGitLabPushTriggerGitlabServerTest {
|
||||||
String excludeBranchesSpec = null;
|
String excludeBranchesSpec = null;
|
||||||
String targetBranchRegex = null;
|
String targetBranchRegex = null;
|
||||||
GitLabPushTrigger gitLabPushTrigger = new GitLabPushTrigger(triggerOnPush, triggerOnMergeRequest,
|
GitLabPushTrigger gitLabPushTrigger = new GitLabPushTrigger(triggerOnPush, triggerOnMergeRequest,
|
||||||
triggerOpenMergeRequestOnPush, ciSkip, setBuildDescription, addNoteOnMergeRequest,
|
triggerOpenMergeRequestOnPush, ciSkip, setBuildDescription, addNoteOnMergeRequest, addCiMessage,
|
||||||
addVoteOnMergeRequest, acceptMergeRequestOnSuccess, branchFilter, includeBranchesSpec,
|
addVoteOnMergeRequest, acceptMergeRequestOnSuccess, branchFilter, includeBranchesSpec,
|
||||||
excludeBranchesSpec, targetBranchRegex);
|
excludeBranchesSpec, targetBranchRegex);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue