Created
September 23, 2011 13:39
-
-
Save knightq/1237346 to your computer and use it in GitHub Desktop.
Script to update jenkins to the latest version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| hudson_home: /home/cruisecontrol/apache-tomcat-6.0.16/webapps/hudson | |
| hudson_ftp: ftp.osuosl.org | |
| hudson_ftp_base_dir: pub/jenkins/war/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'fileutils' | |
| require 'net/ftp' | |
| require 'yaml' | |
| if __FILE__ == $0 | |
| @@config = YAML::load( File.open( 'hudson.yml' ) ) | |
| hudson_home = @@config['hudson_home'] | |
| hudson_ftp = @@config['hudson_ftp'] | |
| hudson_ftp_base_dir = @@config['hudson_ftp_base_dir'] | |
| def get_latest_hudson_war(hudson_ftp, hudson_ftp_base_dir) | |
| puts "hudson_ftp: \"#{hudson_ftp}\"" | |
| puts "hudson_ftp_base_dir: \"#{hudson_ftp_base_dir}\"" | |
| puts "@@config['hudson_home']: \"#{@@config['hudson_home']}\"" | |
| Net::FTP.open(hudson_ftp) do |ftp| | |
| ftp.login | |
| puts ftp.list("#{hudson_ftp_base_dir}") | |
| latest_version_dir = ftp.list("#{hudson_ftp_base_dir}")[-2].split.last | |
| puts "directory di prelievo FTP: \"#{latest_version_dir}\"" | |
| # I file sono ordinati in modo decrescente: l'ultimo è l'ultima versione | |
| files = ftp.chdir("#{hudson_ftp_base_dir}/#{latest_version_dir}") | |
| ftp.getbinaryfile('jenkins.war', "#{@@config['hudson_home']}/jenkins.war", 1024) | |
| end | |
| end | |
| def restart_hudson | |
| system("$HOME/restart_hudson.sh") | |
| end | |
| def unzip(filename) | |
| command = "unzip #{filename} -d #{@@config['hudson_home']}" | |
| success = system(command) | |
| success && $?.exitstatus == 0 | |
| end | |
| if File.exist?(hudson_home) | |
| FileUtils.mkdir "#{hudson_home}/../XML" unless File.exist?("#{hudson_home}/../XML") | |
| x_l_files = Dir.glob("#{hudson_home}/*.x*l"); | |
| FileUtils.cp x_l_files, "#{hudson_home}/../XML/" unless x_l_files.empty? | |
| FileUtils.rm_r Dir.glob("#{hudson_home}/*") | |
| get_latest_hudson_war(hudson_ftp, hudson_ftp_base_dir) | |
| unzip("#{hudson_home}/jenkins.war") | |
| all_from_XML_dir = Dir.glob("#{hudson_home}/../XML/*") | |
| FileUtils.cp_r(all_from_XML_dir, "#{hudson_home}/") unless all_from_XML_dir.empty? | |
| FileUtils.rm_r(Dir.glob("#{hudson_home}/jenkins.war")) | |
| restart_hudson | |
| else | |
| puts "ERRORE - Il percorso \"#{hudson_home}\" non sembra essere valido..." | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, my jenkins server is standlone and i want to upgrade the version to latest jenkins version.. could you please help on this.