Solved the problem, just add an envVars.clear() to the else statement 

On Thursday, November 9, 2017 at 3:58:36 PM UTC-5, Josh Branham wrote:
>
> Any idea how to make this delete all existing key pairs to ensure only the 
> ones defined in this script  are the ones in Jenkins?
>
> On Wednesday, February 25, 2015 at 4:53:27 PM UTC-5, Victor Volle wrote:
>>
>> Final solution:
>>
>> instance = Jenkins.getInstance()
>> globalNodeProperties = instance.getGlobalNodeProperties()
>> envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.
>> EnvironmentVariablesNodeProperty.class)
>>
>> newEnvVarsNodeProperty = null
>> 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("FOO", "foo")
>>
>> instance.save()
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/90f2b3c2-8f92-4ee0-a69c-ad575d863b2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to