Skip to content

Instantly share code, notes, and snippets.

@ivan-pinatti
Last active June 27, 2019 15:06
Show Gist options
  • Save ivan-pinatti/e263ad4dc3e9c74090894c6646438a69 to your computer and use it in GitHub Desktop.
Save ivan-pinatti/e263ad4dc3e9c74090894c6646438a69 to your computer and use it in GitHub Desktop.
Jenkins - Disable CLI via groovy script - #jenkins #groovy
#!groovy
//
// only works on Jenkins version < 2.165
//
// imports
import jenkins.model.Jenkins
// get Jenkins instance
Jenkins jenkins = Jenkins.getInstance()
// disable Jenkins CLI
jenkins.getDescriptor("jenkins.CLI").get().setEnabled(false)
// save current Jenkins state to disk
jenkins.save()
@odoublewen
Copy link

I'm also getting java.lang.NullPointerException: Cannot invoke method get() on null object when trying:

instance.getDescriptor("jenkins.CLI").get().setEnabled(false)

This used to work on Jenkins 2.168, but I recently upgraded to 2.182 and now it doesn't, as far as I can tell.

Just found this gist randomly today, funny that you commented here 3 hrs ago!

@odoublewen
Copy link

I think this may explain my issue:

Remoting-based CLI removed from Jenkins

@ivan-pinatti
Copy link
Author

I think this may explain my issue:

Remoting-based CLI removed from Jenkins

Hi @odoublewen,

Yes, it does explain.
I've added a comment on the header that it only works on Jenkins < 2.165.

I was catching up the comments yesterday because I realized that I never received any notification (don't know why), thanks for your comment btw. :)

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment