Created
January 24, 2019 20:28
-
-
Save imranansari/9d1cb75949ff37f51e080e3532317ec5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.slaves.EnvironmentVariablesNodeProperty; | |
import hudson.slaves.NodeProperty; | |
import hudson.slaves.NodePropertyDescriptor; | |
import hudson.util.DescribableList; | |
import jenkins.model.Jenkins; | |
public createGlobalEnvironmentVariables(String key, String value){ | |
Jenkins instance = Jenkins.getInstance(); | |
DescribableList<NodeProperty<?>, NodePropertyDescriptor> globalNodeProperties = instance.getGlobalNodeProperties(); | |
List<EnvironmentVariablesNodeProperty> envVarsNodePropertyList = globalNodeProperties.getAll(EnvironmentVariablesNodeProperty.class); | |
EnvironmentVariablesNodeProperty newEnvVarsNodeProperty = null; | |
EnvVars 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(key, value) | |
instance.save() | |
} | |
createGlobalEnvironmentVariables('NODE_EXTRA_CA_CERTS','/etc/pki/ca-trust/source/anchors/*.pem') | |
createGlobalEnvironmentVariables('AC_SERVICES_URL','https://geo-qe.miao.apple.com/geo') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment