简体   繁体   English

使用Jenkins Job Builder配置插件

[英]Configuring plugins with Jenkins Job Builder

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. 我正在尝试使用Jenkins Job Builder安装jenkins插件,但是我误解了JJB可以做什么,或者我做错了什么。 I used the get-plugins-info command to get a YAML description of my plugins. 我使用get-plugins-info命令获取插件的YAML描述。 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. 稍后,当重建jenkins安装时,我使用jenkins-jobs -p plugins_info.yaml jobs ,希望JJB将安装YAML文件中列出的插件。 But it didn't install the plugins. 但是它没有安装插件。

So my first question is: should I even expect JJB to install these plugins? 所以我的第一个问题是:我什至希望JJB安装这些插件吗? The documentation for what JJB is doing with the plugin information is limited, so I'm running on assumptions here. JJB处理插件信息的文档是有限的,因此我在这里假设。

Assuming JJB is supposed to be installing the plugins in the YAML file, how can I figure out why it's not? 假设JJB 应该在YAML文件中安装插件,我如何找出为什么没有呢? I've looked at jenkins' logs to no avail. 我看了詹金斯的日志无济于事。

JJB has no capability to manage Jenkins Plugins. JJB无权管理Jenkins插件。 You will need to look into other tools to handle that for you such as puppet, ansible, etc... 您将需要研究其他工具来为您处理这些问题,例如p,ansible等。

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. 在更新命令中使用“ get-plugins-info”和“ -p”参数的情况是,如果系统管理员不想让Jenkins中的所有JJB“管理员”访问权限都将当前安装的插件信息传递给JJB,在更新运行期间“查询”插件信息。 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. 最新版本的Jenkins不再允许匿名查询插件信息,不幸的是将该权限移至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. plugins-info非常有用,因为JJB支持某些插件的多个版本,并且需要知道所安装的版本是什么,以便根据所支持的版本适当地创建XML。

I'll start by mentioning that I use Jenkins Job Builder for creating and versioning my jobs. 首先,我将使用Jenkins Job Builder创建和版本化我的作业。 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. 但是,如果您想以自动方式在Jenkins中安装/配置插件,则可以使用init.groovy.d脚本来初始化jenkins实例。 In order to do so create the following directory ${JENKINS_HOME}/init.groovy.d/ then place your groovy scripts in that directory. 为此,创建以下目录${JENKINS_HOME}/init.groovy.d/然后将groovy脚本放在该目录中。 This is a script that I use to install plugins when I start Jenkins. 这是启动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. 希望这可以帮助您和其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM