Skip to content

Commit

Permalink
[JENKINS-20972] Exception when updating a generated job
Browse files Browse the repository at this point in the history
  • Loading branch information
syl20bnr committed Dec 11, 2013
1 parent 2f84fb0 commit da375e5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main/java/org/jenkinsci/plugins/jobgenerator/GeneratorRun.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit da375e5

Please sign in to comment.