Variable replacement in Jenkins plugin

I am developing a new Jenkins plugin that will be executed during the build phase of the Jenkins task and has the requirement to allow the user to specify the variable name (as opposed to the literal value) in the task configuration for the plugin. It is assumed that when the task is run, the variable name specified by the user will be replaced the real value associated with the variable, and that the plugin will then use that real value when the execution method is run.

For example, if a variable MY_VARIABLEwith a value myValuewas added to the build environment by another part of the task, and the value ${MY_VARIABLE}was specified in the task configuration for my plug-in, then I would like to replace the plug-in with ${MY_VARIABLE}the real value of the variable myValue.

enter image description here

, , Jenkins , . , , - . , , - , , , , .

, Jenkins API , ?

+4
1

- EnvVars, expand(String).

$VARIABLE ${VARIABLE} -style .

:

@Override
public boolean perform(AbstractBuild build, Launcher launcher,
  BuildListener listener) throws IOException, InterruptedException {
    ...
    final EnvVars env = build.getEnvironment(listener);
    String expandedDbUrl = env.expand(dbUrl);
    ...
}
+4

All Articles