Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
update jenkins Updatecenter from CLI
$ java -jar jenkins-cli.jar -s http://localhost:9000 install-plugin findbugs
findbugs is neither a valid file, URL, nor a plugin artifact name in the update center
No update center data is retrieved yet from: http://updates.jenkins-ci.org/update-center.json
findbugs looks like a short plugin name. Did you mean 'null'?
# Specifying a full URL works!
$ java -jar jenkins-cli.jar -s http://localhost:9020 install-plugin http://updates.jenkins-ci.org/download/plugins/AdaptivePlugin/0.1/AdaptivePlugin.hpi
# Get the update center ourself
$ wget -O default.json http://updates.jenkins-ci.org/update-center.json
# remove first and last line javascript wrapper
# Now push it to the update URL
curl -X POST -H "Accept: application/json" -d @default.json http://localhost:9020/updateCenter/byId/default/postBack --verbose
* About to connect() to localhost port 9020 (#0)
* Trying ::1... connected
* Connected to localhost (::1) port 9020 (#0)
> POST /updateCenter/byId/default/postBack HTTP/1.1
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
> Host: localhost:9020
> Accept: application/json
> Content-Length: 253822
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
* Done waiting for 100-continue
< HTTP/1.1 200 OK
< Server: Winstone Servlet Engine v0.9.10
< Content-Type: text/plain;charset=UTF-8
< Connection: Close
< Date: Fri, 01 Apr 2011 13:03:41 GMT
< X-Powered-By: Servlet/2.5 (Winstone/0.9.10)
# Now it finds the plugin by name
$ java -jar jenkins-cli.jar -s http://localhost:9020 install-plugin findbugs
Installing findbugs from update center
$ java -jar jenkins-cli.jar -s http://localhost:9020 safe-restart
hudson.lifecycle.RestartNotSupportedException: Restart is not supported on Mac OS X
$ java -jar jenkins-cli.jar -s http://localhost:9020 reload-configuration
@rowan-m

This comment has been minimized.

Copy link

@rowan-m rowan-m commented Jun 15, 2011

Nice, this solved a problem for me while writing a Chef recipe to install Jenkins.

@ianformanek

This comment has been minimized.

Copy link

@ianformanek ianformanek commented Nov 4, 2011

This was extremely helpful. I derived a bit simpler single line version without the need for saving to a file:

curl  -L http://updates.jenkins-ci.org/update-center.json | sed '1d;$d' | curl -X POST -H 'Accept: application/json' -d @- http://localhost:9020/updateCenter/byId/default/postBack
@elgalu

This comment has been minimized.

Copy link

@elgalu elgalu commented Nov 15, 2013

Here a chef recipe to automate this:

include_recipe 'jenkins'

plugins_to_install = node[:jenkins][:server][:plugins]

# Ensure jenkins user home dir exists
directory "#{node[:jenkins][:server][:home]}" do
  owner "#{node[:jenkins][:server][:user]}"
  group "#{node[:jenkins][:server][:user]}"
  action :create
end

# Fixes possible error:
#   STDOUT: `git` is neither a valid file, URL, nor a plugin artifact name in the update center
#   No update center data is retrieved yet from: http://updates.jenkins-ci.org/update-center.json
directory "#{node[:jenkins][:server][:home]}/updates" do
  owner "#{node[:jenkins][:server][:user]}"
  group "#{node[:jenkins][:server][:user]}"
  action :create
end
execute "update jenkins update center" do
  command "wget http://updates.jenkins-ci.org/update-center.json -qO- | sed '1d;$d'  > #{node[:jenkins][:server][:home]}/updates/default.json"
  user "#{node[:jenkins][:server][:user]}"
  group "#{node[:jenkins][:server][:user]}"
  creates "#{node[:jenkins][:server][:home]}/updates/default.json"
end

# Install all plugins and restart once
jenkins_cli "install-plugin #{plugins_to_install.join(' ')}"
jenkins_cli "safe-restart"
@IcanDivideBy0

This comment has been minimized.

Copy link

@IcanDivideBy0 IcanDivideBy0 commented Oct 13, 2014

Thanks a lot

@ChastinaLi

This comment has been minimized.

Copy link

@ChastinaLi ChastinaLi commented Dec 1, 2016

Why do you need to update UpdateCenter?

@sayantandas

This comment has been minimized.

Copy link

@sayantandas sayantandas commented Feb 10, 2017

This does not work behind a proxy. I always end up getting WARNING: No valid crumb was included in request for /updateCenter/byId/default/postBack. Returning 403.

@tomdev

This comment has been minimized.

Copy link

@tomdev tomdev commented Jun 7, 2017

@sayantandas: This does not work behind a proxy. I always end up getting WARNING: No valid crumb was included in request for /updateCenter/byId/default/postBack. Returning 403.

I don't think that's related to a proxy, rather that Jenkins' CSRF protection is enabled. You should add the crumb as header as well: https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

@jimbo8098

This comment has been minimized.

Copy link

@jimbo8098 jimbo8098 commented Jan 21, 2020

This is still helping people (me). Although it wasn't a direct fix, it made sure I was being sane.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.