Skip to content

Instantly share code, notes, and snippets.

@marcosborges
Created March 16, 2019 12:40
Show Gist options
  • Save marcosborges/aa86ecae8e3b40eadd22ab43862b5686 to your computer and use it in GitHub Desktop.
Save marcosborges/aa86ecae8e3b40eadd22ab43862b5686 to your computer and use it in GitHub Desktop.
import jenkins.*
import jenkins.model.*
class Environment{
def static void write(name, value){
def instance = Jenkins.getInstance()
def globalProps = hudson.model.Hudson.instance.globalNodeProperties
def props = globalProps.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
for (prop in props) {
prop.envVars.put(name,value)
}
instance.save()
}
def static getAll(){
def instance = Jenkins.getInstance()
def globalProps = hudson.model.Hudson.instance.globalNodeProperties
def props = globalProps.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
return props.envVars
}
def static get(name){
def instance = Jenkins.getInstance()
def globalProps = hudson.model.Hudson.instance.globalNodeProperties
def props = globalProps.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
return props.envVars[name]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment