Skip to content

Instantly share code, notes, and snippets.

@basmussen
Created December 30, 2013 14:36
Show Gist options
  • Save basmussen/8182784 to your computer and use it in GitHub Desktop.
Save basmussen/8182784 to your computer and use it in GitHub Desktop.
Install Jenkins plugins
#!/bin/bash
host=http://localhost:8080
url=/pluginManager/installNecessaryPlugins
# git plugin https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
curl -X POST -d '<jenkins><install plugin="[email protected]" /></jenkins>' --header 'Content-Type: text/xml' $host$url
# artifactory plugin https://wiki.jenkins-ci.org/display/JENKINS/Artifactory+Plugin
curl -X POST -d '<jenkins><install plugin="[email protected]" /></jenkins>' --header 'Content-Type: text/xml' $host$url
# wait 20 sec
sleep 20
# jenkins safe restart
curl -X POST $host/safeRestart
@ParagDoke
Copy link

Was trying to see if this can help automate installing plugins at older versions.

Me and a colleague noticed that the version value isn't handled well from a plugin install perspective.
That "installNecessaryPlugins" seems to simply compare whether plugin version from update center json data is newer than what was requested. Unless we got that wrong, have you had success trying to get artifactory plugin version 2.2.1 deployed (now that latest version is 2.4.0) ?

@mkocikowski
Copy link

I found that plugin version is ignored. This is a simplified call to install the "git" plugin (note the @current):

curl -XPOST http://localhost:8080/pluginManager/installNecessaryPlugins -d '<install plugin="git@current" />'

Jenkins v1.644 Thank you very much for the original post!

@icnocop
Copy link

icnocop commented Feb 5, 2016

In regards to the plugin version issue, I created a bug report here: https://issues.jenkins-ci.org/browse/JENKINS-32793

@joesteele
Copy link

A possible workaround is downloading the .hpi files directly into the plugins dir.

sudo -u jenkins wget -P /var/lib/jenkins/plugins https://updates.jenkins-ci.org/download/plugins/git/2.0/git.hpi

@uttamanand
Copy link

Getting the below error while executing the command curl -XPOST http://localhost:8080/pluginManager/installNecessaryPlugins -d ''

HTTP ERROR 403

Problem accessing /pluginManager/installNecessaryPlugins. Reason:

No valid crumb was included in the request

Powered by Jetty://

@tsangacw
Copy link

curl -u admin:admin 'http://localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'

and add the result as header to your request to pluginManager.

@Amor64
Copy link

Amor64 commented Apr 16, 2018

Does anyone successfully able to install jenkins plugin with specific version ?

@espoelstra
Copy link

@Amor64 there is this note and it is also mentioned in the bug filed above.

The Update Center only allows the installation of the most recently released version of a plugin. In cases where an older release of the plugin is desired, a Jenkins administrator can download an older .hpi archive and manually install that on the Jenkins master.

Via the Jenkins CLI this means you need to pass a full URL to the older plugin version, whether that is from the Jenkins Update Center (which keeps the older versions but doesn't index them) or from your own artifact store like Artifactory or Nexus.

@espoelstra
Copy link

So I kept trying this with Jenkins 2.145 but just getting redirected to the updateCenter page and never actually triggering a plugin installation. After much looking I found a comment where somebody mentioned you don't need the XML data and can just pass a form submission of -F "plugin.$PLUGIN.default=on" to $JENKINS_HOST/pluginManager/install and it will trigger the installation. I haven't tested passing multiple plugins at once yet, but the $PLUGIN bit is simply the 'short name' of the plugin which is what is most often used anyways. Because it uses updateCenter you probably can't pass a specific version (updateCenter always pulls latest), but I haven't fully experimented with all the options.

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