-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality to add the new publisher automatically to old jobs …
…if addCiMessage was activated for the GitLabPushTrigger
- Loading branch information
1 parent
8b9c886
commit 9c62979
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/dabsquared/gitlabjenkins/migration/JobConfigMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.dabsquared.gitlabjenkins.migration; | ||
|
||
import com.dabsquared.gitlabjenkins.GitLabPushTrigger; | ||
import com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher; | ||
import com.thoughtworks.xstream.converters.UnmarshallingContext; | ||
import hudson.Plugin; | ||
import hudson.model.Descriptor; | ||
import hudson.model.Items; | ||
import hudson.model.Project; | ||
import hudson.tasks.Publisher; | ||
import hudson.util.DescribableList; | ||
import hudson.util.XStream2; | ||
|
||
/** | ||
* This plugin registers a {@link XStream2.PassthruConverter} that migrates jobs that have the {@link GitLabPushTrigger} | ||
* configured to use the new publisher ({@link GitLabCommitStatusPublisher} if necessary. | ||
* | ||
* @author Robin Müller | ||
*/ | ||
public class JobConfigMigration extends Plugin { | ||
|
||
@Override | ||
public void start() throws Exception { | ||
Items.XSTREAM2.registerConverter(new XStream2.PassthruConverter<Project<?, ?>>(Items.XSTREAM2) { | ||
@Override | ||
protected void callback(Project<?, ?> project, UnmarshallingContext context) { | ||
GitLabPushTrigger trigger = project.getTrigger(GitLabPushTrigger.class); | ||
if (trigger != null) { | ||
DescribableList<Publisher, Descriptor<Publisher>> publishers = project.getPublishersList(); | ||
publishers.setOwner(NOOP); | ||
if (trigger.getAddCiMessage()) { | ||
publishers.add(new GitLabCommitStatusPublisher()); | ||
trigger.setAddCiMessage(false); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean canConvert(Class type) { | ||
return Project.class.isAssignableFrom(type); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters