-
Bug
-
Resolution: Postponed
-
Major
-
None
-
not applicable
Hi there,
I may have found a sneaky bug. Custom environment variables can be defined by the user into the general & nodes config:
When a build is triggered by an SCM change, those variables are not available for SCM plugins.
Let's say that I have a field in my SCM plugin configured with this value: ${JOB_NAME}_${HOSTNAME}_${NODE_TYPE} If the build is triggered by an SCM change I get this error:
Started by an SCM change Building remotely on vmo426 [ClearCase] ### Begin source code retrieval ### cleartool error: Illegal characters found in view name : ${NODE_TYPE}. An environment variable may have not been resolved. Finished: FAILURE
Here is the code snipet from my plugin that does that:
@Override public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, BuildListener listener, File changelogFile) throws IOException, InterruptedException { try { logger.log("### Begin source code retrieval ###"); String resolvedViewName = build.getEnvironment(listener).expand(this.viewName); Pattern pattern = Pattern.compile("(\\$\\{.+?\\})"); Matcher matcher = pattern.matcher(resolvedViewName); if (matcher.find()) { String message = "Illegal characters found in view name : %s. " + "An environment variable may have not been resolved."; throw new ClearToolError(String.format(message, matcher.group())); }
I removed ${NODE_TYPE} from my SCM configuration to let the build continue. And the user custom environment variables seem to be injected into the build environment after the SCM checkout.
Started by an SCM change Building remotely on vmo426 [ClearCase] ### Begin source code retrieval ### ... [ClearCase] === End source code retrieval === [polling_linux] $ /bin/sh -xe /tmp/hudson7589128551511062241.sh + env ... NODE_TYPE=SLAVE ...
Could this be fixed?
I think environment variables defined in node properties are not available in AbstractBuild.getEnvironment(TaskListener) method.
I think it doesn't work in your use case because you have maybe created your own launcher.
Therefore, the following code is not available
for (NodeProperty nodeProperty: Hudson.getInstance().getGlobalNodeProperties()) {
{ buildEnvironments.add(environment); }Environment environment = nodeProperty.setUp(AbstractBuild.this, l, listener);
if (environment != null)
}
for (NodeProperty nodeProperty: Computer.currentComputer().getNode().getNodeProperties()) {
Environment environment = nodeProperty.setUp(AbstractBuild.this, l, listener);
if (environment != null) { buildEnvironments.add(environment); }
}
located in AbstractBuild#createLauncher() method
A better alternative is to use the great EnvInject plugin
With it, in your SCM code, just get the EnvInjectAction and its captured environment variables (used in my forked SCM clearcase plugin).