Skip to content

Instantly share code, notes, and snippets.

@pwillis-els
Last active December 31, 2020 05:39
Show Gist options
  • Save pwillis-els/63c6d3bf260ef29068b49dd117b6362d to your computer and use it in GitHub Desktop.
Save pwillis-els/63c6d3bf260ef29068b49dd117b6362d to your computer and use it in GitHub Desktop.
Jenkins Cheat Sheet

Plugins

What plugins are installed on my Jenkins server?

  • There are "Downloaded plugins" and there are "Bundled plugins".
    • Bundled plugins come in the jenkins.war file which contains the Jenkins Core code. You may need to check for security updates for these separate from your downloaded plugins. When you change your Jenkins Core version, you'll want to re-check these plugins.
    • Downloaded plugins must be downloaded and installed aside from the jenkins.war file.
  • Plugins can have a .jpi' or .hpi file extension.

From the filesystem

Bundled

# List the bundled plugins in jenkins.war
$ unzip -qql jenkins.war 'WEB-INF/detached-plugins/*.*pi' | sed -e 's/[[:space:]]\+/ /g' | cut -d ' ' -f 5
# List all the bundled plugin versions
$ tmp=`mktemp`; \
  for i in $(unzip -qql jenkins.war 'WEB-INF/detached-plugins/*.*pi' | sed -e 's/[[:space:]]\+/ /g' | cut -d ' ' -f 5) ; do \
      unzip -p jenkins.war "$i" > "$tmp" ; \
      unzip -p $tmp META-INF/MANIFEST.MF | grep -e "Extension-Name\|Plugin-Version" | tr -d '\r' | tr '\n' ' ' | sed -e 's/Extension-Name: //g; s/ Plugin-Version: /:/g;' ; \
      echo "" ; \
  done ; rm -f "$tmp"

Downloaded

# The shared 'ref/' folder is copied on start-up by Jenkins to /var/jenkins_home/plugins/
$ cd /usr/share/jenkins/ref/plugins
$ for i in *.[jh]pi ; do \
      unzip -p "$i" META-INF/MANIFEST.MF | grep -e "Extension-Name\|Plugin-Version" | tr -d '\r' | tr '\n' ' ' | sed -e 's/Extension-Name: //g; s/ Plugin-Version: /:/g;' ; \
      echo "" ; \
  done

Notes

  • If Jenkins is reporting a version of a plugin that doesn't make sense to you, it's probably because an old version of the plugin is still hanging around somewhere. If you have previously installed plugins (such as to /usr/share/jenkins/ref/plugins, or /var/jenkins_home/plugins), they will stick around until you remove them. And there are plugins bundled with Jenkins Core which may need to be updated after you have run Jenkins for the first time.
  • A record of what plugins have been installed by Jenkins (on first start-up, usually) can be found in /var/jenkins_home/copy_reference_file.log.
  • A cached file /var/jenkins_home/updates/default.json contains the latest versions of plugins.

Jenkins Configuration as Code

Assuming the plugin is installed in Jenkins, pass the environment variable CASC_JENKINS_CONFIG to Jenkins at runtime. The value must be one of:

  • Path to a folder containing a set of config files. For example, /var/jenkins_home/casc_configs.
  • A full path to a single file. For example, /var/jenkins_home/casc_configs/jenkins.yaml.
  • A URL pointing to a file served on the web. For example, https://acme.org/jenkins.yaml. The value will be searched recursively for any .yml, .yaml, .YAML, .YML file extensions. The path must also contain no hidden folders.

You can alternately use the Java property casc.jenkins.config.

If none of the above is set, the default config file is $JENKINS_HOME/jenkins.yaml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment