333...@gmail.com
unread,Apr 3, 2020, 1:56:44 AM4/3/20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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()