Skip to content
Permalink
Browse files
[JENKINS-20972] Exception when updating a generated job
  • Loading branch information
syl20bnr committed Dec 11, 2013
1 parent 2f84fb0 commit da375e54af06b3532ce7b576d99a29fab5d15dad
Showing 1 changed file with 14 additions and 8 deletions.
@@ -31,6 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
import hudson.model.Result;
import hudson.model.TopLevelItem;
import hudson.model.AbstractBuild;
import hudson.model.AbstractItem;
import hudson.model.AbstractProject;
import hudson.model.Cause;
import hudson.model.ParametersAction;
@@ -65,6 +66,8 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.transform.stream.StreamSource;

import jenkins.model.Jenkins;

import org.apache.tools.ant.filters.StringInputStream;
@@ -412,19 +415,22 @@ protected Result doRun(BuildListener listener) throws Exception {
InputStream is = new ByteArrayInputStream(
doc.asXML().getBytes("UTF-8"));
// System.out.println(doc.asXML());
boolean created =
Jenkins.getInstance().getItem(expName) == null;
if(created){
LOGGER.info(String.format("Created job %s", expName));
}
else{
AbstractItem item =
(AbstractItem) Jenkins.getInstance().getItem(expName);
if(item != null){
StreamSource ss = new StreamSource(is);
item.updateByXml(ss);
LOGGER.info(String.format("Updated configuration of " +
"job %s", expName));
}
Jenkins.getInstance().createProjectFromXML(expName, is);
else{
Jenkins.getInstance().createProjectFromXML(expName, is);
LOGGER.info(String.format("Created job %s", expName));
}
// save generated job name
GeneratedJobBuildAction action =
new GeneratedJobBuildAction(expName, created);
new GeneratedJobBuildAction(expName, item!=null);
getBuild().addAction(action);
getBuild().addAction(action);
}
return Result.SUCCESS;

0 comments on commit da375e5

Please sign in to comment.