Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #3 from ydubreuil/fix-JENKINS-26958
[JENKINS-26958]: workflow plugin compatibility
  • Loading branch information
gboissinot committed Jul 25, 2015
2 parents c5608d7 + 12b7e95 commit 45c34ad
Showing 1 changed file with 21 additions and 18 deletions.
Expand Up @@ -18,9 +18,7 @@
public class ZenTimestampEnvironmentContributor extends EnvironmentContributor {

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

AbstractBuild build = (AbstractBuild) r;
public void buildEnvironmentFor(Run run, EnvVars envs, TaskListener listener) throws IOException, InterruptedException {

String pattern = null;

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

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

//Get local node pattern and override it if any
Node node = build.getBuiltOn();

//Check if the node is already up
// --> Build can be a previous build (case of polling) and the node can be no more exists
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
Job job = getJob(build);
Job job = getJob(run);
ZenTimestampJobProperty zenTimestampJobProperty = (ZenTimestampJobProperty) job.getProperty(ZenTimestampJobProperty.class);
if (zenTimestampJobProperty != null) {
pattern = zenTimestampJobProperty.getPattern();
Expand All @@ -55,19 +58,19 @@ public void buildEnvironmentFor(Run r, EnvVars envs, TaskListener listener) thro
//Process pattern
if (pattern != null) {
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));
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
final String formattedBuildValue = sdf.format(buildTimestamp.getTime());
envs.put(ZenTimestampAction.BUILD_TIMESTAMP_VARIABLE, formattedBuildValue);
}
}

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

0 comments on commit 45c34ad

Please sign in to comment.