Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update jenkins plugins from the terminal?

I am trying to create a bash script for setting up Jenkins. Is there any way to update a plugin list from the Jenkins terminal?

At first setup there is no plugin available on the list

i.e.:

java -jar jenkins-cli.jar -s `http://localhost:8080` install-plugin dry

won't work

like image 424
anilyeni Avatar asked Oct 10 '11 08:10

anilyeni


People also ask

How do I update Jenkins from command line?

There is no way to update the Jenkins version via the Jenkins CLI. If you installed Jenkins as a standalone WAR file, all you need to do to upgrade it from the command line is to download the new Jenkins WAR file and replace your current WAR file, then restart Jenkins.

Where is Jenkins plugin CLI?

By default it will be in ~/. cache/jenkins-plugin-management-cli , if the user doesn't have a home directory when it will go to: $(pwd)/. cache/jenkins-plugin-management-cli .

Can we Install plugin using Jenkins CLI?

Using the Jenkins CLI. It is also possible to enable or disable plugins via the Jenkins CLI using the enable-plugin or disable-plugin commands. The enable-plugin command was added to Jenkins in v2.

How do I access the terminal in Jenkins?

Browser access to the terminal The first is through a browser. To get there, go to the page that shows an on-going build, then click "Interactive Terminal". You'll have to press the "Launch a terminal" button to start a session.


4 Answers

A simple but working way is first to list all installed plugins, look for updates and install them.

java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ list-plugins

Each plugin which has an update available, has the new version in brackets at the end. So you can grep for those:

java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ list-plugins | grep -e ')$' | awk '{ print $1 }'

If you call install-plugin with the plugin name, it is automatically upgraded to the latest version.

Finally you have to restart jenkins.

Putting it all together (can be placed in a shell script):

UPDATE_LIST=$( java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ list-plugins | grep -e ')$' | awk '{ print $1 }' );  if [ ! -z "${UPDATE_LIST}" ]; then      echo Updating Jenkins Plugins: ${UPDATE_LIST};      java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ install-plugin ${UPDATE_LIST};     java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ safe-restart; fi 
like image 116
Michael Wyraz Avatar answered Nov 01 '22 10:11

Michael Wyraz


You can actually install plugins from the computer terminal (rather than the Jenkins terminal).

  1. Download the plugin from the plugin site (http://updates.jenkins-ci.org/download/plugins)
  2. Copy that plugin into the $JENKINS_HOME/plugins directory
  3. At that point either start Jenkins or call the reload settings service (http://yourservername:8080/jenkins/reload)

This will enable the plugin in Jenkins and assuming that Jenkins is started.

cd $JENKINS_HOME/plugins curl -O http://updates.jenkins-ci.org/download/plugins/cobertura.hpi curl http://yourservername:8080/reload 
like image 32
Jon Boydell Avatar answered Nov 01 '22 10:11

Jon Boydell


Here is how you can deploy Jenkins CI plugins using Ansible, which of course is used from the terminal. This code is a part of roles/jenkins_ci/tasks/main.yaml:

- name: Plugins
  with_items:                             # PLUGIN NAME
  - name: checkstyle                      # Checkstyle
  - name: dashboard-view                  # Dashboard View
  - name: dependency-check-jenkins-plugin # OWASP Dependency Check
  - name: depgraph-view                   # Dependency Graph View
  - name: deploy                          # Deploy
  - name: emotional-jenkins-plugin        # Emotional Jenkins
  - name: monitoring                      # Monitoring
  - name: publish-over-ssh                # Publish Over SSH
  - name: shelve-project-plugin           # Shelve Project
  - name: token-macro                     # Token Macro
  - name: zapper                          # OWASP Zed Attack Proxy (ZAP)
  sudo: yes
  get_url: dest="{{ jenkins_home }}/plugins/{{ item.name | mandatory }}.jpi"
           url="https://updates.jenkins-ci.org/latest/{{ item.name }}.hpi"
           owner=jenkins group=jenkins mode=0644
  notify: Restart Jenkins

This is a part of a more complete example that you can find at: https://github.com/sakaal/service_platform_ansible/blob/master/roles/jenkins_ci/tasks/main.yaml

Feel free to adapt it to your needs.

like image 37
SAM Avatar answered Nov 01 '22 08:11

SAM


You can update plugins list with this command line

curl -s -L http://updates.jenkins-ci.org/update-center.json | sed '1d;$d' | curl -s -X POST -H 'Accept: application/json' -d @- http://localhost:8080/updateCenter/byId/default/postBack
like image 34
IcanDivideBy0 Avatar answered Nov 01 '22 09:11

IcanDivideBy0