JENKINS - GLOBAL VARS

5 views
Skip to first unread message

333...@gmail.com

unread,
Apr 3, 2020, 1:56:44 AM4/3/20
to Jenkins Users
I ask for urgent help.
I have a code that adds a global variable to Jenkins, it works, but the pipeline is always FAILED, but there are no errors in Console. Why is the pipeline FAILED and how can I fix it?
p. s. Tried to insert in try-catch, but still FAILED.

Code:

import hudson.slaves.EnvironmentVariablesNodeProperty
import jenkins.model.Jenkins

instance = Jenkins.getInstance()
globalNodeProperties = instance.getGlobalNodeProperties()
envVarsNodePropertyList = globalNodeProperties.getAll(EnvironmentVariablesNodeProperty.class)

newEnvVarsNodeProperty = null
envVars = null

if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0 ) {
newEnvVarsNodeProperty = new EnvironmentVariablesNodeProperty();
globalNodeProperties.add(newEnvVarsNodeProperty)
envVars = newEnvVarsNodeProperty.getEnvVars()
} else {
envVars = envVarsNodePropertyList.get(0).getEnvVars()

envVars.put("snapshot_id", "Sample Groovy Global Var 3")
instance.save()

Reply all
Reply to author
Forward
0 new messages