9

I do a lot of testing in my Jenkins VM which I have on my local laptop. I found this time-consuming to remove Jenkins and installing again from scratch. It would be better if I have a simple way to restore my Jenkins.

Is there a way to remove all the plugins that I have installed manually and keep the plugins that were installed during Jenkins installation?

030
  • 13,235
  • 16
  • 74
  • 173
Buvanesh Kumar
  • 467
  • 3
  • 5
  • 13
  • Why do you want that? – 030 Mar 08 '18 at 21:48
  • I don't think there is a universal "one-click" button to restore default plugins. You can however download and search through the jenkins.war file of the version you installed and see the exact plugins with their versions that are bundled with that version. – Preston Martin Mar 08 '18 at 22:01
  • 1
    @030 I'm going to assume he is fed up with trying to figure out which plugins are causing him issues and wants to start from square 1 :) – Preston Martin Mar 08 '18 at 22:01
  • @030 I do a lot of testing in my Jenkins VM which I have on my local laptop. I found it time-consuming to remove Jenkins and installing again from scratch. It would be better if I have a simple way to restore my Jenkins in a simple way. – Buvanesh Kumar Mar 09 '18 at 15:35
  • @030 I have added the same :) – Buvanesh Kumar Mar 09 '18 at 18:31
  • Once you start installing any of the plugin, it automatically install the ones that are to be installed by default – Ajith Babu Oct 29 '19 at 09:16

4 Answers4

3

One could also use docker Jenkins LTS. If one wants to start from scratch, just remove the mounted Jenkins home folder and there will be a clean Jenkins in no time.

https://github.com/jenkinsci/docker/blob/master/README.md

030
  • 13,235
  • 16
  • 74
  • 173
  • Yup, I have used this procedure sometimes back, still using some cases. I'm just curious to know is there a native way of doing this. – Buvanesh Kumar Mar 09 '18 at 18:33
  • You could mount the docker image and attach your jenkins home folder to it. Then you can run a script/program/whatever that compares the plugins and deletes the ones that are in your jenkins home but not in the docker container's jenkins home. – Lee Meador Nov 12 '19 at 18:05
2

One could use ansible geerlingguy.jenkins role. When this role is applied, a Jenkins system will be created without any plugins. Subsequently, one could install plugins manually, but also define them in ansible, i.e. plugins as code.

030
  • 13,235
  • 16
  • 74
  • 173
2

One possible approach, although a bit tedious (and a bit dumb), would be to:

  • make a fresh Jenkins installation of the exact same version on another (maybe scrappable) machine
  • get the list of the (default) plugins it ends up with
  • add/remove/update the plugins in the original Jenkins installation to match that list
Dan Cornilescu
  • 6,730
  • 2
  • 19
  • 44
2

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:

  • jenkins.yml
  • plugins.txt

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.

Bruce Becker
  • 3,573
  • 4
  • 19
  • 40