I find it strange that nobody mentioned the Configuration as Code plugin. Our solution to this problem is to maintain a base Docker image for jenkins, provisioned with two config files:
The plugins are installed by the install-plugins.sh
script provided by the base Jenkins image:
COPY casc_configs/plugins.txt /usr/share/jenkins/ref/plugins.txt
COPY casc_configs/jenkins.yml /usr/share/jenkins/ref/jenkins.yml
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt
and Jenkins itself is configured using the jenkins.yml
.
The plugin file is generated from a template:
{% for plugin in jenkins.plugins %}
{{ plugin.name }}:{{ plugin.version }}
{%endfor%}
where the variable jenkins.plugins
is a big list of dicts:
jenkins:
plugins:
- name: configuration-as-code
version: 1.14
Doing things this way makes it possible to create and destroy fully configured jenkins instances on the fly. If you want, you can keep the jenkins.yml
and plugins.txt
on a mount that Jenkins can read when it starts.