如何创建不同的Jenkins2图像,解锁和预装插件?

时间:2016-11-11 11:11:59

标签: jenkins docker dockerfile

我基于official Jenkins image启动了一个新的Jenkins2容器。

但是,它需要初始设置。必须输入随机生成的解锁字符串,并且必须设置admin user / pass。然后必须安装插件。

我希望能够从dockerfile中设置它们。

我列出了我想在构建期间安装的插件,但是我如何面对其他两个?

基本上,我希望能够创建独特配置的不同图像,并准备通过容器使用。

1 个答案:

答案 0 :(得分:1)

插件

安装插件(根据documentation):

# Dockerfile

USER root
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt

# (...)
USER jenkins

如果您希望生成 plugins.txt ,在运行上述内容之前,请根据您当前的手动jenkins设置运行以下命令:

JENKINS_HOST=<user>:<passwd>@<hostname>:<port>
curl -sSL "http://$JENKINS_HOST/pluginManager/api/xml?depth=1&xpath=/*/*/shortName|/*/*/version&wrapper=plugins" | perl -pe 's/.*?<shortName>([\w-]+).*?<version>([^<]+)()(<\/\w+>)+/\1 \2\n/g'|sed 's/ /:/' > plugins.txt

_

# plugins.txt (example)

ace-editor:1.1
git-client:2.1.0
workflow-multibranch:2.9.2
script-security:1.24
durable-task:1.12
pam-auth:1.3
credentials:2.1.8
bitbucket:1.1.5
ssh-credentials:1.12
credentials-binding:1.10
mapdb-api:1.0.9.0
workflow-support:2.10
resource-disposer:0.3
workflow-basic-steps:2.3
email-ext:2.52
ws-cleanup:0.32
ssh-slaves:1.11
workflow-job:2.9
docker-commons:1.5
matrix-project:1.7.1
plain-credentials:1.3
workflow-scm-step:2.3
scm-api:1.3
matrix-auth:1.4
icon-shim:2.0.3
ldap:1.13
pipeline-build-step:2.3
subversion:2.7.1
ant:1.4
branch-api:1.11.1
pipeline-input-step:2.5
bouncycastle-api:2.16.0
workflow-cps:2.23
docker-slaves:1.0.5
cloudbees-folder:5.13
pipeline-stage-step:2.2
workflow-api:2.6
pipeline-stage-view:2.2
workflow-aggregator:2.4
github:1.22.4
token-macro:2.0
pipeline-graph-analysis:1.2
authentication-tokens:1.3
handlebars:1.1.1
gradle:1.25
git:3.0.0
external-monitor-job:1.6
structs:1.5
mercurial:1.57
antisamy-markup-formatter:1.5
jquery-detached:1.2.1
mailer:1.18
workflow-cps-global-lib:2.4
windows-slaves:1.2
workflow-step-api:2.5
docker-workflow:1.9
github-branch-source:1.10
pipeline-milestone-step:1.1
git-server:1.7
github-organization-folder:1.5
momentjs:1.1.1
build-timeout:1.17.1
github-api:1.79
workflow-durable-task-step:2.5
pipeline-rest-api:2.2
junit:1.19
display-url-api:0.5
timestamper:1.8.7

禁用安全性&amp;管理员用户

可以通过将 - env JAVA_OPTS =&#34; -Djenkins.install.runSetupWizard = false&#34; 传递给 docker run 命令进行排序。< / p>

示例:

docker run -d --name myjenkins -p 8080:8080 -p 50000:50000 --env JAVA_OPTS="-Djenkins.install.runSetupWizard=false" jenkins:latest