Skip to content

Instantly share code, notes, and snippets.

@thomasbiddle
Last active December 16, 2015 00:49
Show Gist options
  • Save thomasbiddle/5350078 to your computer and use it in GitHub Desktop.
Save thomasbiddle/5350078 to your computer and use it in GitHub Desktop.
Grabbing an environment variable from Jenkins
// Assuming environment is an EnvVars object, and mergeOptions is an arbitrary object that, when I call getMergeOptions(), returns the branch I'm merging with - Which can either be a string - or an environment variable, $some_var
String mergeTarget = "";
if ( environment.get(mergeOptions.getMergeTarget()) != null ) {
mergeTarget = environment.get(mergeOptions.getMergeTarget().substring(1));
} else {
mergeTarget = mergeOptions.getMergeTarget();
}
vs...
mergeTarget = environment.expand(mergeOptions.getMergeTarget());
// I'm assuming the second one is the correct way to do it here :-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment