-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports promoted-builds plugin (thanks @juanpablo-santos)
- Loading branch information
Marc Carter
committed
Jun 23, 2015
1 parent
4fd1585
commit 6f8e956
Showing
4 changed files
with
75 additions
and
1 deletion.
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
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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/joelj/jenkins/eztemplates/promotedbuilds/PromotedBuildsTemplateUtils.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,57 @@ | ||
package com.joelj.jenkins.eztemplates.promotedbuilds; | ||
|
||
import hudson.Util; | ||
import hudson.model.AbstractProject; | ||
import hudson.plugins.promoted_builds.JobPropertyImpl; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
|
||
|
||
/** | ||
* Utility class to handle the promoted builds plugin. | ||
*/ | ||
public class PromotedBuildsTemplateUtils { | ||
|
||
private static Logger LOG = Logger.getLogger("ez-templates"); | ||
|
||
/** | ||
* Adds all the promotions from the template project into the implementation one. All existing promotions from the | ||
* implementation project are lost. | ||
* | ||
* @param implementationProject | ||
* @param templateProject | ||
* @throws IOException | ||
*/ | ||
public static void addPromotions(AbstractProject implementationProject, AbstractProject templateProject) throws IOException { | ||
|
||
JobPropertyImpl promotions = (JobPropertyImpl) implementationProject.getProperty(JobPropertyImpl.class); | ||
if (promotions != null) { | ||
LOG.info(String.format("Merging [%s].", promotions.getFullDisplayName())); | ||
|
||
// remove existing promotions on implementationProject, if any | ||
implementationProject.removeProperty(JobPropertyImpl.class); | ||
Util.deleteRecursive(new File(implementationProject.getRootDir(), "promotions")); | ||
promotions.getItems().clear(); | ||
|
||
// obtain templateProject promotions. Each promotion is stored under a different folder under $JOB/promotions | ||
File templatePromotions = new File(templateProject.getRootDir(), "promotions"); | ||
String[] list = templatePromotions.list(); | ||
if (list != null) { | ||
for (String promotionDir : list) { | ||
File templatePromotionProcess = new File(templatePromotions, promotionDir); | ||
if (templatePromotionProcess.isDirectory()) { | ||
// for each promotion, create a process from its configuration | ||
promotions.createProcessFromXml(promotionDir, new FileInputStream(new File(templatePromotionProcess, "config.xml"))); | ||
} | ||
} | ||
} | ||
|
||
// update implementationProject with the resulting promotions | ||
implementationProject.addProperty(promotions); | ||
} | ||
} | ||
|
||
} |
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