Skip to content

Commit

Permalink
Move macro replacement into the if
Browse files Browse the repository at this point in the history
  • Loading branch information
slide committed Aug 17, 2016
1 parent 8d81d3c commit bd60183
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
13 changes: 3 additions & 10 deletions pom.xml
Expand Up @@ -4,14 +4,14 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.3</version>
<version>2.12</version>
</parent>

<properties>
<jenkins.version>1.642.2</jenkins.version>
<java.level>7</java.level>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pipeline.version>1.10</pipeline.version>
<pipeline.version>2.1</pipeline.version>
</properties>

<licenses>
Expand Down Expand Up @@ -65,7 +65,7 @@
<dependency>
<groupId>org.parboiled</groupId>
<artifactId>parboiled-java</artifactId>
<version>1.0.2</version>
<version>1.1.7</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down Expand Up @@ -107,13 +107,6 @@
<version>${pipeline.version}</version>
<scope>test</scope>
</dependency>
<dependency> <!-- StepConfigTester -->
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<classifier>tests</classifier>
<version>${pipeline.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/org/jenkinsci/plugins/tokenmacro/TokenMacro.java
Expand Up @@ -29,17 +29,27 @@
import hudson.FilePath;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.BuildVariableContributor;
import hudson.model.BuildableItemWithBuildWrappers;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.Run;
import hudson.model.TaskListener;
import org.apache.commons.lang.StringUtils;
import hudson.tasks.BuildWrapper;
import hudson.util.VariableResolver;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
import org.apache.tools.ant.taskdefs.Parallel;


/**
* A macro that expands to text values in the context of a {@link AbstractBuild}.
Expand Down Expand Up @@ -213,9 +223,10 @@ public static String expandAll(Run<?,?> run, FilePath workspace, TaskListener li
// Expand environment variables
stringWithMacro = stringWithMacro.replaceAll("\\$\\$", "\\$\\$\\$\\$");
String s = run.getEnvironment(listener).expand(stringWithMacro);
// Expand build variables
s = s.replaceAll("\\$\\$", "\\$\\$\\$\\$");

if(run instanceof AbstractBuild) {
// Expand build variables
s = s.replaceAll("\\$\\$", "\\$\\$\\$\\$");
AbstractBuild<?,?> build = (AbstractBuild<?, ?>)run;
s = Util.replaceMacro(s, build.getBuildVariableResolver());
}
Expand Down

0 comments on commit bd60183

Please sign in to comment.