Home > Net >  Groovy script returns null object with the job names including forward slash
Groovy script returns null object with the job names including forward slash

Time:11-21

I am trying to disable some jobs in Jenkins with the following script but it doesn't work with the names including "/" in it.

This one works fine:

String jobName = 'randomjobName'
Jenkins.instance.getItem(jobName).setDisabled(true)

But this one does not work:

String jobName = 'random/jobName'
Jenkins.instance.getItem(jobName).setDisabled(true)

it returns:

java.lang.NullPointerException: Cannot invoke method setDisabled() on null object
    at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)

I have searched everywhere but I could not find any solution. Any ideas?

I have tried different jobs but no solution so far.

CodePudding user response:

Try the following.

String jobName = 'random/jobName'
Jenkins.instance.getItemByFullName(jobName).setDisabled(true)
  • Related