简体   繁体   English

从dockerfile中的github安装jenkins插件

[英]Install jenkins plugin from github in dockerfile

I have a simple Dockerfile where I install Jenkins and some plugins: 我有一个简单的Dockerfile,我安装Jenkins和一些插件:

FROM jenkins/jenkins:2.169-alpine

USER root
RUN apk update \
    && apk add --no-cache curl docker jq tzdata \
    && rm -rf /var/cache/apk/*

COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/plugins.txt

There is now a jenkins plugin with a custom patch I would need to include. 现在有一个jenkins插件,我需要包含一个自定义补丁。 There's already a PR open for it but it's been months it was not merged and I can't wait anymore, so I'd like to add a step to install a plugin from a branch of my github repo. 已经开放了PR,但它已经好几个月没有合并,我不能再等了,所以我想添加一个步骤从我的github repo的分支安装一个插件。

I found out that after the jenkins-cli.jar is available (so, not at build time), one can install a plugin in hpi format doing: 我发现在jenkins-cli.jar可用之后(因此,不是在构建时),可以安装hpi格式的插件:

java -jar /var/jenkins_home/war/WEB-INF/jenkins-cli.jar \\ -auth user:password \\ -s http://localhost:8080 install-plugin file://<HPI_PATH>

but it cannot work at build time. 但它无法在构建时工作。 If not possible in the dockerfile, is there an alternative? 如果在dockerfile中不可能,还有替代方案吗?

First build the plugin.hpi locally and then Use copy or Add in Dockerfile to add plugin into jenkins docker images in build step. 首先在本地构建plugin.hpi,然后在构建步骤中使用复制或Add in Dockerfile将插件添加到jenkins docker镜像中。

example Add https://updates.jenkins-ci.org/download/plugins/sonar/2.8.1/sonar.hpi /var/jenkins_home/plugins/ 示例添加https://updates.jenkins-ci.org/download/plugins/sonar/2.8.1/sonar.hpi / var / jenkins_home / plugins /

Or 要么

Install sonar plugin using local build hpi file. 使用本地生成hpi文件安装声纳插件。

Copy sonar.hpi /var/jenkins_home/plugins/ 复制sonar.hpi / var / jenkins_home / plugins /

After digging PR, I found the solution here https://github.com/jenkinsci/docker/pull/799 挖掘PR之后,我在这里找到了解决方案https://github.com/jenkinsci/docker/pull/799

This is not an install from github but it will work out 这不是github的安装,但它会解决

So you just need to add at the end of your dockerfile (being root and not jenkins user): 所以你只需要在dockerfile的末尾添加(是root而不是jenkins用户):

RUN /usr/local/bin/install-plugins.sh plugin-name:plugin-version:hpi-url

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

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