First posted on Jenkins Chinese community

Manual installation of Jenkins plugins

In general, there are two ways to install the Jenkins plugin. The first method is to go to the Jenkins Plugin management page to search for the plugin and install it. The second method is to upload the Jenkins plug-in HPI file to install. These two approaches satisfy the needs of most people.

The first method is shown in the figure below:

The second method is shown in the figure below:

However, for students who need to ensure Jenkins stability or carry out secondary development on Jenkins, the above methods cannot meet the needs.

The first is that the version of the plug-in cannot be specified. The second way is to find the plug-in’s dependency tree and install it one by one based on the dependencies. Yes, Jenkins will not automatically download dependencies for manually uploading the plugin.

In addition, neither method can achieve batch installation.

A method for automatically installing plug-ins

So, is there a way to specify the version of the plug-in, download its dependencies automatically, and download them in bulk?

Fortunately, the install-plugins.sh script in Jenkins’ Docker image repository is already implemented. We just need to bring it in for a little modification. After modification, the author created the corresponding code repository: Jenkins-install-plugins-shell. The link is at the end of the article.

Jenkins-install-plugins-shell

  1. Clone the code into the JENKINS_HOME directory.
cd $JENKINS_HOME
git clone https://github.com/zacker330/jenkins-install-plugins-shell.git
cd jenkins-install-plugins-shell
Copy the code
  1. Add the plugins you want to install to plugins.txtjenkins-install-plugins-shellIn the directory, you have a plugins.txt file in which you write the plug-in you want to install and the version number. Such as:
Powershell ansible: 1.0:1.3Copy the code
  1. Perform the installation
 # Jenkins War path for analysis
exportJENKINS_WAR_PATH=<Jenkins war file path > chmod +x install-plugins.sh jenkins-support./install-plugins.sh < plugins.txtCopy the code
  1. Restarting Jenkins install-plugins essentially does nothing more than download plug-ins from the cloud into the plugins directory under JENKINS_HOME. Jenkins also needs to be restarted for the installed plug-in to take effect.

About the name of the Jenkins plugin

The Jenkins plugin has two names. One is called display name and one is called short name. For example, the Disply name of Ansible plug-in is Ansible Plugin, and the short name is Ansible.

How do YOU know the short name of a plug-in? It can be found on the Jenkins plugin website, such as Ansible:

Short names are used in plugins.txt.

conclusion

Why did I decide on the Jenkins plugin version? Because the version of the plug-in affects the reliability of Jenkins pipeline. That’s why I care so much about the Jenkins plugin version.

The appendix

  • The automatic plug-in installation script in Jenkins’ official Docker image: github.com/jenkinsci/d…
  • The author modified the automatic plug-in installation script: github.com/zacker330/j…

Author: Zhai Zhijun