0.02
No commit activity in last 3 years
No release in over 3 years
List, find and create Jenkins jobs on a Jenkins CI server
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.6.0
>= 0
~> 2.8.0
~> 1.7.10

Runtime

~> 0.7.6
~> 0.3.2
 Project Readme

Jenkins::Client travis Dependency Status

This gem can be used for listing, finding and creating Jenkins jobs on a Jenkins CI server from Ruby or command-line.

Installation

Add this line to your application's Gemfile:

gem 'jenkins-client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jenkins-client

Command-Line Usage

The jenkins-client library comes with a convenient command-line interface. The following command lists all available Jenkins jobs.

jenkins --url jenkins.example.com:8080 -u jenkins -p password jobs

Run jenkins --help for more information.

JSON

The command-line client will return structured JSON data when specifying --json.

jenkins --url jenkins.example.com:8080 -u jenkins -p password --json jobs

Libary Usage

In rails add an initialiser like this

client = Jenkins::Client.new
client.username = "user"
client.password = "pass"
client.url = "http://jenkinsurl.com"

Then you can issue the following commands in your app.

Jobs

Retrieve a hash of jobs with the job name as key.

client.jobs.each_pair do |name, job|
  puts "#{name}: #{job.color}"
end

Create

Create a new Jenkins job on the server with a given configuration.

job = Jenkins::Client::Job.new({ :name => "job_name" })
job.create!(config)

Jenkins uses XML config files on the server and this is what you should send as the config.

<?xml version='1.0' encoding='UTF-8'?>
<project>
  <actions/>
  <description></description>
  <keepDependencies>false</keepDependencies>
  <properties/>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>true</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <triggers class="vector"/>
  <concurrentBuild>false</concurrentBuild>
  <builders/>
  <publishers/>
  <buildWrappers/>
</project>

To export an existing config simply look in the jobs path inside your Jenkins server and pull back a job's config.xml file.

Start

Starts a job.

job = Jenkins::Client::Job.new({ :name => "job_name" })
job.start!

Delete

Delete a Jenkins job on the server.

job = Jenkins::Client::Job.new({ :name => "job_name" })
job.delete!

Last Build

Retrieve the last build.

job.last_build # last build
job.last_successful_build # last successful build
job.last_failed_build # last failed build

Build

Retrieve the console text of a build.

job.last_failed_build.console_text

Changelog/History

Can be found here.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request