Reputation: 357
I'd like to set Jenkins Global Properties - Environment variables via Groovy script (YAML file) which is executed in Ansible.
I've tried following
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
instance = Jenkins.getInstance()
envVars.put("FOO1", "bar1")
envVars.put("FOO2", "bar2")
instance.save()
Why is this not working?
Upvotes: 1
Views: 8324
Reputation: 357
Done in this way:
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
instance = Jenkins.getInstance()
globalNodeProperties = instance.getGlobalNodeProperties()
envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
envVars = null
if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0 ) {
newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty();
globalNodeProperties.add(newEnvVarsNodeProperty)
envVars = newEnvVarsNodeProperty.getEnvVars()
} else {
envVars = envVarsNodePropertyList.get(0).getEnvVars()
}
envVars.put("name", "value")
instance.save()
Upvotes: 7