Enable Jenkins CLI across all controllers

1 minute read

Issue

Resolution

Please make sure that all Jenkins controllers are connected to your CloudBees Jenkins Operations Center.

Create a New Item of type Cluster Operation:

create cluster op

Under the Operation center configuration screen select Add Operation and select Managed controllers:

cluster ops controllers

Then select From Operations Center Root and under the Filters select Is Online:

cluster op is online

In the Steps section click on Add Step and select Execute Groovy Script on controller:

cluster op groovy script

Then paste the following:

import java.nio.file.Files
import java.nio.file.Paths


def jenkins_home = Jenkins.get().getRootDir().absolutePath
def initDirPath = Paths.get(jenkins_home, "init.groovy.d")
def groovyFile = initDirPath.toRealPath().toString() + "/cli-shutdown.groovy"

try {
  // Delete file that disable CLI protocols
  // get enabled upon Jenkins controller restarting
  File file = new File(groovyFile)
  file.delete()
} catch (all) {
  println "Unable to delete '$groovyFile'. " +
          "If controller restarts, must apply this script again"
}

Then click Save. Finally execute the cluster operation by clicking run:

run cluster op

This should then run the script on all of the controllers. Once run, you will need to restart the controller so that the CLI extensions can be loaded again.

Please be aware you might not need to restart to enable CLI through SSH. This can be done anytime in the UI by an admin user under Manage JenkinsSecurity.