Enable Jenkins CLI across all controllers

Article ID:235037108
1 minute readKnowledge base

Issue

Environment

  • CloudBees Jenkins Operations Center

  • Private Saas Edition

Resolution

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

Click "New Item":

new item

Next click on 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 env = System.getenv()
def jhome = env['JENKINS_HOME']
def initDir = "$jhome/init.groovy.d"
def initDirPath = Paths.get(initDir)
def groovyFile = "$initDir/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.