Extract Multiple Jenkins Plugin JAR Files from BASH

From Bonus Bits
Jump to: navigation, search


This article gives the steps to quickly extract the JAR files from multiple Jenkins Plugin files (.hpi/jpi) from a BASH CLI. This can be useful if you have a bunch of plugins and want to pull the jar files out to a Groovy IntelliJ IDEA project library folder so you to get all the libraries in your classpath.


  • rename package
    • brew install rename
    • yum install rename

Copy Plugins from Master

One way to get all the plugin libraries currently being used by you Jenkins Master for you Groovy project is to simply copy the archive files from the master.

  1. SSH to the Jenkins Master
  2. tar up the .hpi and .jpi files. They are already compressed so no real benefit to gzipping.
    tar -cvf ~/jenkins_plugins.tar /opt/jenkins/plugins/*.[j|h]pi
  3. Copy the tar to your workstation
  4. Extract the tar. Strip components 3 removes 3 levels of directories i.e. opt/jenkins/plugins. Or if we are in the directory when we tarred the files and used . instead of the Full Path it wouldn't have the directories in the tar and we can drop the strip components argument.
    mkdir -p /tmp/jenkins_plugins && tar -xvf ~/jenkins_plugins.tar -C /tmp/jenkins_plugins --strip-components 3

Rename Files

The .hpi and .jpi files are simply zip files. I found the quickest way was to simply rename the files to zip.

rename "s/[j|h]pi/zip/" *.[j|h]pi

Extract Jars

So if you want the first command output to go say in the middle of a command instead of just at the end you can use the -I {} argument to set the variable name and {} where you want the output to land in the command.

ls *.zip | xargs -I {} unzip -oj {} "WEB-INF/lib/*" -d /path/to/lib

Related Articles