Skip to content
Permalink
Browse files

[JENKINS-26958]: workflow plugin compatibility

  • Loading branch information...
ydubreuil committed Jun 19, 2015
1 parent c5608d7 commit 12b7e9517e28038b1281d4cdf2f08b6cc9eb0ce1
Showing with 21 additions and 18 deletions.
  1. +21 −18 src/main/java/hudson/plugins/zentimestamp/ZenTimestampEnvironmentContributor.java
@@ -18,9 +18,7 @@
public class ZenTimestampEnvironmentContributor extends EnvironmentContributor { public class ZenTimestampEnvironmentContributor extends EnvironmentContributor {


@Override @Override
public void buildEnvironmentFor(Run r, EnvVars envs, TaskListener listener) throws IOException, InterruptedException { public void buildEnvironmentFor(Run run, EnvVars envs, TaskListener listener) throws IOException, InterruptedException {

AbstractBuild build = (AbstractBuild) r;


String pattern = null; String pattern = null;


@@ -32,21 +30,26 @@ public void buildEnvironmentFor(Run r, EnvVars envs, TaskListener listener) thro
} }
} }


//Get local node pattern and override it if any if (run instanceof AbstractBuild) {
Node node = build.getBuiltOn(); AbstractBuild build = (AbstractBuild) run;
//Check if the node is already up
// --> Build can be a previous build (case of polling) and the node can be no more exists //Get local node pattern and override it if any
if (node != null) { Node node = build.getBuiltOn();
for (NodeProperty<?> nodeProperty : node.getNodeProperties()) {
if (nodeProperty instanceof ZenTimestampNodeProperty) { //Check if the node is already up
ZenTimestampNodeProperty envInjectNodeProperty = (ZenTimestampNodeProperty) nodeProperty; // --> Build can be a previous build (case of polling) and the node can be no more exists
pattern = envInjectNodeProperty.getPattern(); if (node != null) {
for (NodeProperty<?> nodeProperty : node.getNodeProperties()) {
if (nodeProperty instanceof ZenTimestampNodeProperty) {
ZenTimestampNodeProperty envInjectNodeProperty = (ZenTimestampNodeProperty) nodeProperty;
pattern = envInjectNodeProperty.getPattern();
}
} }
} }
} }


//Get job pattern and override it if any //Get job pattern and override it if any
Job job = getJob(build); Job job = getJob(run);
ZenTimestampJobProperty zenTimestampJobProperty = (ZenTimestampJobProperty) job.getProperty(ZenTimestampJobProperty.class); ZenTimestampJobProperty zenTimestampJobProperty = (ZenTimestampJobProperty) job.getProperty(ZenTimestampJobProperty.class);
if (zenTimestampJobProperty != null) { if (zenTimestampJobProperty != null) {
pattern = zenTimestampJobProperty.getPattern(); pattern = zenTimestampJobProperty.getPattern();
@@ -55,19 +58,19 @@ public void buildEnvironmentFor(Run r, EnvVars envs, TaskListener listener) thro
//Process pattern //Process pattern
if (pattern != null) { if (pattern != null) {
final PrintStream logger = listener.getLogger(); final PrintStream logger = listener.getLogger();
Calendar buildTimestamp = build.getTimestamp(); Calendar buildTimestamp = run.getTimestamp();
//logger.println(String.format("Changing " + ZenTimestampAction.BUILD_TIMESTAMP_VARIABLE + " variable (job build time) with the date pattern %s.", pattern)); //logger.println(String.format("Changing " + ZenTimestampAction.BUILD_TIMESTAMP_VARIABLE + " variable (job build time) with the date pattern %s.", pattern));
SimpleDateFormat sdf = new SimpleDateFormat(pattern); SimpleDateFormat sdf = new SimpleDateFormat(pattern);
final String formattedBuildValue = sdf.format(buildTimestamp.getTime()); final String formattedBuildValue = sdf.format(buildTimestamp.getTime());
envs.put(ZenTimestampAction.BUILD_TIMESTAMP_VARIABLE, formattedBuildValue); envs.put(ZenTimestampAction.BUILD_TIMESTAMP_VARIABLE, formattedBuildValue);
} }
} }


private Job getJob(AbstractBuild build) { private Job getJob(Run run) {
if (build instanceof MatrixRun) { if (run instanceof MatrixRun) {
return ((MatrixRun) build).getParentBuild().getProject(); return ((MatrixRun) run).getParentBuild().getProject();
} else { } else {
return build.getProject(); return run.getParent();
} }
} }
} }

0 comments on commit 12b7e95

Please sign in to comment.
You can’t perform that action at this time.