0

I'm trying to use Jenkins Job Builder to install jenkins plugins, but I misunderstand what JJB can do or I'm doing something wrong. I used the get-plugins-info command to get a YAML description of my plugins. Later, when rebuilding the jenkins installation, I used jenkins-jobs -p plugins_info.yaml jobs in the hopes that JJB would install the plugins listed in the YAML file. But it didn't install the plugins.

So my first question is: should I even expect JJB to install these plugins? The documentation for what JJB is doing with the plugin information is limited, so I'm running on assumptions here.

Assuming JJB is supposed to be installing the plugins in the YAML file, how can I figure out why it's not? I've looked at jenkins' logs to no avail.

abingham
  • 1,294
  • 1
  • 10
  • 17

2 Answers2

1

I'll start by mentioning that I use Jenkins Job Builder for creating and versioning my jobs. But if you want to install/configure plugins in Jenkins in an automated fashion you can use init.groovy.d scripts that will initialize your jenkins instance. In order to do so create the following directory ${JENKINS_HOME}/init.groovy.d/ then place your groovy scripts in that directory. This is a script that I use to install plugins when I start Jenkins.

import jenkins.model.*
import java.util.logging.Logger

def logger = Logger.getLogger("")
def installed = false
def initialized = false
def plugins = ["git", "cloudbees-folder", "build-timeout"]

logger.info("" + plugins)
def instance = Jenkins.getInstance()
def pm = instance.getPluginManager()
def uc = instance.getUpdateCenter()
plugins.each {
  logger.info("Checking " + it)
  if (!pm.getPlugin(it)) {
    logger.info("Looking UpdateCenter for " + it)
    if (!initialized) {
      uc.updateAllSites()
      initialized = true
    }
    def plugin = uc.getPlugin(it)
    if (plugin) {
      logger.info("Installing " + it)
        def installFuture = plugin.deploy()
      while(!installFuture.isDone()) {
        logger.info("Waiting for plugin install: " + it)
        sleep(3000)
      }
      installed = true
    }
  }
}
if (installed) {
  logger.info("Plugins installed, initializing a restart!")
  instance.save()
  instance.restart()
}

Add as many plugin names to the array plugins. Hope this help you and others out.

nabello
  • 716
  • 11
  • 29
0

JJB has no capability to manage Jenkins Plugins. You will need to look into other tools to handle that for you such as puppet, ansible, etc...

The usage for "get-plugins-info" and the "-p" parameter in the update command is to pass currently installed plugin info to JJB in cases where a system administrator does not want to all JJB "administrator" access permissions in Jenkins to "query" plugin info during the update run. The latest versions of Jenkins no longer allows anonymous querying of plugin info and unfortunately moved that permission to the administrator permission inside of Jenkins.

plugins-info is useful because JJB supports multiple versions of certain plugins and needs to know what the installed version is to appropriately create the XML depending on supported versions.

zxiiro
  • 92
  • 5