Created
March 27, 2017 03:04
-
-
Save haneefs/cff1d67da8875c4e74b988ab0c8a507d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hudson.EnvVars | |
import hudson.model.* | |
def build_number = Job.getVariable("BUILD_NUMBER") | |
def type = Job.getVariable("Type1") | |
if (type.equalsIgnoreCase("ALL")){ | |
Job.setVariable("Type", "None") | |
} | |
def name = Job.getVariable("Name") | |
if (name == null || name.length() == 0){ | |
Job.setVariable("Name", "None") | |
} | |
class Job { | |
static def getVariable(String key) { | |
def config = new HashMap() | |
def thr = Thread.currentThread() | |
def build = thr?.executable | |
def envVarsMap = build.parent.builds[0].properties.get("envVars") | |
config.putAll(envVarsMap) | |
return config.get(key) | |
} | |
static def setVariable(String key, String value) { | |
def build = Thread.currentThread().executable | |
def action = new VariableInjectionAction(key, value) | |
build.addAction(action) | |
build.getEnvironment() | |
} | |
} | |
class VariableInjectionAction implements EnvironmentContributingAction { | |
private String key | |
private String value | |
public VariableInjectionAction(String key, String value) { | |
this.key = key | |
this.value = value | |
} | |
public void buildEnvVars(AbstractBuild build, EnvVars envVars) { | |
if (envVars != null && key != null && value != null) { | |
envVars.put(key, value); | |
} | |
} | |
public String getDisplayName() { | |
return "VariableInjectionAction"; | |
} | |
public String getIconFileName() { | |
return null; | |
} | |
public String getUrlName() { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment