Last active
June 27, 2019 15:06
-
-
Save ivan-pinatti/e263ad4dc3e9c74090894c6646438a69 to your computer and use it in GitHub Desktop.
Jenkins - Disable CLI via groovy script - #jenkins #groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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() |
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!
I think this may explain my issue:
I think this may explain my issue:
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
Hi @madhusaragadam,
What version of Jenkins are you running? Are you running it directly into Jenkins Script Console?
Cheers!