hudson-remote-api is ruby library to talk to Hudson's xml remote access api
gem install hudson-remote-api
require 'hudson-remote-api'
# Auto Configuration
# detects Hudson instance on your network & sets the host name
Hudson.auto_configure
Or
# Manual Configuration
settings = {
:host => 'http://localhost:8080',
:user => 'hudson',
:password => 'password',
:version => '1.0',
:crumb => true, # To turn on/off checking for crumbIssuer
:proxy_host => 'your-proxy-host', # To turn on proxy access
:proxy_port => 888
}
Hudson.client(settings)
# list all jobs
Hudson::Job.list
# list current active jobs
Hudson::Job.list_active
# list all jobs in the build queue (waiting to run)
Hudson::BuildQueue.list
j = Hudson::Job.new('my_new_job')
j = Hudson::Job.new('my_new_job')
# start a build
j.build
# start a parameterized build. Pass parameters as a Hash.
j.build({ :awesome_dev => "thomasbiddle" })
# create a copy of existing job
j.copy('copy_of_my_job')
# disable the job
j.disable
# enable the job
j.enable
# clear out the job's workspace
j.wipe_out_workspace
# wait (sleep) until the job has completed building
j.wait_for_build_to_finish
# delete the job
j.delete
j = Hudson::Job.new('job_name')
# job's current build indicator color
puts j.color
# returns true if job is currently running
j.active?
# list of job's build numbers
puts j.builds_list
# latest build number
puts j.last_build
# latest successful build number
puts j.last_successful_build
# latest failed build number
puts j.last_failed_build
# next build number
puts j.next_build_number
# view current triggers
# returns hash containing trigger name in key and trigger spec in value.
# Example: {"hudson.triggers.TimerTrigger"=>"0 22 * * *", "hudson.triggers.SCMTrigger"=>"* * * * *"}
j.triggers
# gets information on latest build
b = Hudson::Build.new('job_name')
# gets information on particular build number
b = Hudson::Build.new('job_name', 42)
# get commit revisions in this build
puts b.revisions
# get the result of this build
puts b.result
# get the culprit of this build
puts b.culprit
j.description = "My new job description"
# Git
j.repository_url = { :url => 'https://github.com/beeplove/hudson-remote-api-mkhan.git', :branch => 'origin/master' }
# or, only to change branch
j.repository_url = { :branch => 'origin/master' }
# SVN
j.repository_url = "http://svn.myrepo.com"
j.triggers = { 'hudson.triggers.SCMTrigger' => '* * * * *'}
# or, using shortcut
j.triggers = { 'SCMTrigger' => '* * * * *', 'TimerTrigger' => '0 22 * * *'}
# Add or update a trigger in existing triggers*
j.triggers = j.triggers.merge({ 'hudson.triggers.TimerTrigger' => '0 22 * * *'})
# Delete existing triggers
j.triggers = {}
# or,
j.triggers = nil
*Avoid using shortcut form when editing a trigger in existing triggers
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request