Navigation Menu

Skip to content

Commit

Permalink
[FIXED JENKINS-18004] add support for TokenMacros
Browse files Browse the repository at this point in the history
  • Loading branch information
imod committed May 19, 2013
1 parent a394d7e commit c6150ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
6 changes: 5 additions & 1 deletion pom.xml
Expand Up @@ -38,6 +38,11 @@
<artifactId>config-file-provider</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>token-macro</artifactId>
<version>1.6</version>
</dependency>
</dependencies>

<repositories>
Expand Down Expand Up @@ -122,5 +127,4 @@
</plugins>
</pluginManagement>
</build>

</project>
Expand Up @@ -33,6 +33,7 @@
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.managedscripts.ScriptConfig.Arg;
import org.jenkinsci.plugins.managedscripts.ScriptConfig.ScriptConfigProvider;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.bind.JavaScriptMethod;
Expand Down Expand Up @@ -153,9 +154,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

// Add additional parameters set by user
if (buildStepArgs != null) {
final VariableResolver<String> variableResolver = build.getBuildVariableResolver();
for (String arg : buildStepArgs) {
args.add(resolveVariable(variableResolver, arg));
args.add(TokenMacro.expandAll(build, listener, arg, false, null));
}
}

Expand Down Expand Up @@ -292,25 +292,4 @@ private ConfigProvider getBuildStepConfigProvider() {
}

}

/**
* Checks whether the given parameter is a build parameter and if so, returns the value of it.
*
* @param variableResolver
* resolver to be used
* @param potentalVariable
* the potential variable string. The string will be treated as variable, if it follows this pattern: ${XXX}
* @return value of the build parameter or the origin passed string
*/
private String resolveVariable(VariableResolver<String> variableResolver, String potentalVariable) {
String value = potentalVariable;
if (potentalVariable != null) {
if (potentalVariable.startsWith("${") && potentalVariable.endsWith("}")) {
value = potentalVariable.substring(2, potentalVariable.length() - 1);
value = variableResolver.resolve(value);
log.log(Level.FINE, "resolve " + potentalVariable + " to " + value);
}
}
return value;
}
}

0 comments on commit c6150ef

Please sign in to comment.