jenkins-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +7 -0
- data/bin/build +11 -0
- data/jenkins-rails.gemspec +25 -0
- data/lib/jenkins-rails.rb +34 -0
- data/lib/jenkins-rails/configuration.rb +44 -0
- data/lib/jenkins-rails/ext.rb +170 -0
- data/lib/jenkins-rails/railtie.rb +7 -0
- data/lib/jenkins-rails/tasks/jenkins.rake +6 -0
- data/lib/jenkins-rails/version.rb +3 -0
- data/spec/fixtures/files/build +3 -0
- data/spec/jenkins-rails/configuration_spec.rb +16 -0
- data/spec/jenkins-rails/ext_spec.rb +74 -0
- data/spec/jenkins-rails_spec.rb +16 -0
- data/spec/jenkins.yml +10 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/rspec_helpers.rb +14 -0
- metadata +138 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 anguyen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# jenkins-rails [![Build Status](https://travis-ci.org/anhkind/jenkins-rails.png?branch=master)](https://travis-ci.org/anhkind/jenkins-rails) [![Dependency Status](https://gemnasium.com/anhkind/jenkins-rails.png)](https://gemnasium.com/anhkind/jenkins-rails)
|
2
|
+
|
3
|
+
***jenkins-rails*** is a Ruby gem to automate configuration tasks of a Rails app on Jenkins CI server. The configuration will be just as easy as adding a .yml file to the Rails config folder, then run rake task to set it up on Jenkins.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'jenkins-rails', :git => 'git://github.com/anhkind/jenkins-rails.git'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
### Configuration
|
19
|
+
|
20
|
+
Create `jenkins.yml` file (with `erb`) as following structure and put to **Rails config folder**:
|
21
|
+
|
22
|
+
username: <%= ENV['JENKINS_USERNAME'] %>
|
23
|
+
password: <%= ENV['JENKINS_PASSWORD'] %>
|
24
|
+
host: <%= ENV['JENKINS_HOST'] %>
|
25
|
+
jobs
|
26
|
+
-
|
27
|
+
name: 'Job 1' #compulsory
|
28
|
+
scm_provider: 'git' #compulsory
|
29
|
+
scm_url: 'git://github.com/apraditya/sampleapp.git' #compulsory
|
30
|
+
scm_branch: 'master' #optional, default is 'master' if scm is git
|
31
|
+
shell_script: 'relative/path/to/build/script' #optional, details below
|
32
|
+
keep_dependencies: false #optional, default is 'false'
|
33
|
+
block_build_when_downstream_building: false #optional, default is 'false'
|
34
|
+
block_build_when_upstream_building: false #optional, default is 'false'
|
35
|
+
concurrent_build: false #optional, default is 'false'
|
36
|
+
child_projects: ~ #optional, default is 'null'
|
37
|
+
child_threshold: failure #optional, value is 'success', 'failure', or 'unstable'
|
38
|
+
# default is 'failure'
|
39
|
+
-
|
40
|
+
name: 'Job 2'
|
41
|
+
...
|
42
|
+
|
43
|
+
The option `shell_script` can be configured with the **relative** path of the build script from Rails app root path, e.g. `'script/jenkins_build_script'`, `'config/jenkins_build_script'` ...
|
44
|
+
|
45
|
+
### Rake task
|
46
|
+
After adding the `jenkins.yml` to Rails app config folder, run the following rake task to configure Jenkins jobs
|
47
|
+
|
48
|
+
rake jenkins:configure
|
49
|
+
|
50
|
+
If username and password in `jenkins.yml` are empty or the environment variables are not set, the rake task can be run as following:
|
51
|
+
|
52
|
+
rake jenkins:configure[jenkins_username, jenkins_password]
|
53
|
+
|
54
|
+
For more details, have a look at `rake -T` in your Rails app.
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/build
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/bin/bash -x
|
2
|
+
|
3
|
+
export CI_REPORTS=results
|
4
|
+
export RAILS_ENV=test
|
5
|
+
|
6
|
+
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" >/dev/null 2>&1
|
7
|
+
|
8
|
+
cp config/database.yml.example config/database.yml
|
9
|
+
bundle install
|
10
|
+
bundle exec rake db:create db:migrate
|
11
|
+
bundle exec rake
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jenkins-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "jenkins-rails"
|
8
|
+
gem.version = Jenkins::VERSION
|
9
|
+
gem.authors = ["Anh Nguyen"]
|
10
|
+
gem.email = ["anhkind@gmail.com"]
|
11
|
+
gem.description = %q{Jenkins integration for Rails}
|
12
|
+
gem.summary = %q{Jenkins integration for Rails}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency "jenkins_api_client", ">= 0.5.0"
|
21
|
+
|
22
|
+
gem.add_development_dependency "rake"
|
23
|
+
gem.add_development_dependency "rspec", ">= 2.11"
|
24
|
+
gem.add_development_dependency "builder"
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "jenkins-rails/version"
|
2
|
+
require "jenkins-rails/ext"
|
3
|
+
require "jenkins-rails/configuration"
|
4
|
+
require "jenkins-rails/railtie" if defined?(Rails)
|
5
|
+
|
6
|
+
module Jenkins
|
7
|
+
GEM_ROOT = File.join(File.dirname(__FILE__), '..')
|
8
|
+
|
9
|
+
def self.configure(options)
|
10
|
+
@configuration ||= Configuration.new(options[:config_file] || Rails.root.join('config', 'jenkins.yml'))
|
11
|
+
jobs_params = @configuration.params
|
12
|
+
|
13
|
+
@client = JenkinsApi::Client.new(
|
14
|
+
:server_ip => @configuration.host,
|
15
|
+
:username => options[:username] || @configuration.username,
|
16
|
+
:password => options[:password] || @configuration.password
|
17
|
+
)
|
18
|
+
|
19
|
+
jobs_params.each do |job_params|
|
20
|
+
client.job.fast_configure(job_params.merge(
|
21
|
+
:name => URI::encode(job_params[:name]),
|
22
|
+
:username => @configuration.username
|
23
|
+
))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.client
|
28
|
+
@client
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.configuration
|
32
|
+
@configuration
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Jenkins
|
2
|
+
class Configuration
|
3
|
+
def initialize(config_file)
|
4
|
+
raise "Config file #{config_file} is missing!" if !File.exist? config_file
|
5
|
+
@config_file = config_file
|
6
|
+
end
|
7
|
+
|
8
|
+
def username
|
9
|
+
config[:username]
|
10
|
+
end
|
11
|
+
|
12
|
+
def password
|
13
|
+
config[:password]
|
14
|
+
end
|
15
|
+
|
16
|
+
def host
|
17
|
+
config[:host]
|
18
|
+
end
|
19
|
+
|
20
|
+
def jobs
|
21
|
+
config[:jobs] ||= []
|
22
|
+
end
|
23
|
+
|
24
|
+
def params
|
25
|
+
jobs.each_index do |i|
|
26
|
+
jobs[i][:shell_command] = File.read(script_file(jobs[i][:shell_script]))
|
27
|
+
end
|
28
|
+
jobs
|
29
|
+
end
|
30
|
+
|
31
|
+
def config
|
32
|
+
@config ||= ActiveSupport::HashWithIndifferentAccess.new(YAML.load(ERB.new(File.read(@config_file)).result))
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def script_file(path)
|
37
|
+
path ? Rails.root.join(path) : default_shell_file
|
38
|
+
end
|
39
|
+
|
40
|
+
def default_shell_file
|
41
|
+
File.join(Jenkins::GEM_ROOT, 'bin', 'build')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'jenkins_api_client'
|
2
|
+
|
3
|
+
module JenkinsApi
|
4
|
+
class Client
|
5
|
+
class Job
|
6
|
+
def fast_create(params)
|
7
|
+
xml = xml_config(params)
|
8
|
+
create(params[:name], xml)
|
9
|
+
end
|
10
|
+
|
11
|
+
def fast_configure(params)
|
12
|
+
xml = xml_config(params)
|
13
|
+
post_config(params[:name], xml)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Create xml from given params
|
17
|
+
#
|
18
|
+
# @param [Hash] params
|
19
|
+
# * +:name+ name of the job
|
20
|
+
# * +:keep_dependencies+ true or false
|
21
|
+
# * +:block_build_when_downstream_building+ true or false
|
22
|
+
# * +:block_build_when_upstream_building+ true or false
|
23
|
+
# * +:concurrent_build+ true or false
|
24
|
+
# * +:scm_provider+ type of source control system. Supported: git, subversion
|
25
|
+
# * +:scm_url+ remote url for scm
|
26
|
+
# * +:scm_branch+ branch to use in scm. Uses master by default
|
27
|
+
# * +:shell_command+ command to execute in the shell
|
28
|
+
# * +:child_projects+ projects to add as downstream projects
|
29
|
+
# * +:child_threshold+ threshold for child projects. success, failure, or unstable. Default: failure.
|
30
|
+
#
|
31
|
+
def xml_config(params)
|
32
|
+
supported_scm_providers = ['git', 'subversion']
|
33
|
+
|
34
|
+
# Set default values for params that are not specified and Error handling.
|
35
|
+
raise 'Job name must be specified' unless params[:name]
|
36
|
+
params[:keep_dependencies] = false if params[:keep_dependencies].nil?
|
37
|
+
params[:block_build_when_downstream_building] = false if params[:block_build_when_downstream_building].nil?
|
38
|
+
params[:block_build_when_upstream_building] = false if params[:block_build_when_upstream_building].nil?
|
39
|
+
params[:concurrent_build] = false if params[:concurrent_build].nil?
|
40
|
+
|
41
|
+
# SCM configurations and Error handling. Presently only Git plugin is supported.
|
42
|
+
unless supported_scm_providers.include?(params[:scm_provider]) || params[:scm_provider].nil?
|
43
|
+
raise "SCM #{params[:scm_provider]} is currently not supported"
|
44
|
+
end
|
45
|
+
raise 'SCM URL must be specified' if params[:scm_url].nil? && !params[:scm_provider].nil?
|
46
|
+
params[:scm_branch] = "master" if params[:scm_branch].nil? && !params[:scm_provider].nil?
|
47
|
+
|
48
|
+
# Child projects configuration and Error handling
|
49
|
+
params[:child_threshold] = 'failure' if params[:child_threshold].nil? && !params[:child_projects].nil?
|
50
|
+
|
51
|
+
# Build the Job xml file based on the parameters given
|
52
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') { |xml|
|
53
|
+
xml.project {
|
54
|
+
xml.actions
|
55
|
+
xml.description
|
56
|
+
xml.keepDependencies "#{params[:keep_dependencies]}"
|
57
|
+
xml.properties {
|
58
|
+
xml.send("hudson.security.AuthorizationMatrixProperty") {
|
59
|
+
xml.permission "hudson.model.Item.Configure:#{params[:username]}"
|
60
|
+
xml.permission "hudson.model.Item.Read:#{params[:username]}"
|
61
|
+
xml.permission "hudson.model.Item.Discover:#{params[:username]}"
|
62
|
+
xml.permission "hudson.model.Item.Build:#{params[:username]}"
|
63
|
+
xml.permission "hudson.model.Item.Workspace:#{params[:username]}"
|
64
|
+
xml.permission "hudson.model.Item.Cancel:#{params[:username]}"
|
65
|
+
xml.permission "hudson.model.Run.Delete:#{params[:username]}"
|
66
|
+
xml.permission "hudson.model.Run.Update:#{params[:username]}"
|
67
|
+
xml.permission "hudson.scm.SCM.Tag:#{params[:username]}"
|
68
|
+
}
|
69
|
+
}
|
70
|
+
# SCM related stuff
|
71
|
+
if params[:scm_provider] == 'subversion'
|
72
|
+
xml.scm(:class => "hudson.scm.SubversionSCM", :plugin => "subversion@1.39") {
|
73
|
+
xml.locations {
|
74
|
+
xml.send("hudson.scm.SubversionSCM_-ModuleLocation") {
|
75
|
+
xml.remote "#{params[:scm_url]}"
|
76
|
+
xml.local "."
|
77
|
+
}
|
78
|
+
}
|
79
|
+
xml.excludedRegions
|
80
|
+
xml.includedRegions
|
81
|
+
xml.excludedUsers
|
82
|
+
xml.excludedRevprop
|
83
|
+
xml.excludedCommitMessages
|
84
|
+
xml.workspaceUpdater(:class => "hudson.scm.subversion.UpdateUpdater")
|
85
|
+
}
|
86
|
+
elsif params[:scm_provider] == 'git'
|
87
|
+
xml.scm(:class => "hudson.plugins.git.GitSCM") {
|
88
|
+
xml.configVersion "2"
|
89
|
+
xml.userRemoteConfigs {
|
90
|
+
xml.send("hudson.plugins.git.UserRemoteConfig") {
|
91
|
+
xml.name
|
92
|
+
xml.refspec
|
93
|
+
xml.url "#{params[:scm_url]}"
|
94
|
+
}
|
95
|
+
}
|
96
|
+
xml.branches {
|
97
|
+
xml.send("hudson.plugins.git.BranchSpec") {
|
98
|
+
xml.name "#{params[:scm_branch]}"
|
99
|
+
}
|
100
|
+
}
|
101
|
+
xml.disableSubmodules "false"
|
102
|
+
xml.recursiveSubmodules "false"
|
103
|
+
xml.doGenerateSubmoduleConfigurations "false"
|
104
|
+
xml.authorOrCommitter "false"
|
105
|
+
xml.clean "false"
|
106
|
+
xml.wipeOutWorkspace "false"
|
107
|
+
xml.pruneBranches "false"
|
108
|
+
xml.remotePoll "false"
|
109
|
+
xml.ignoreNotifyCommit "false"
|
110
|
+
xml.useShallowClone "false"
|
111
|
+
xml.buildChooser(:class => "hudson.plugins.git.util.DefaultBuildChooser")
|
112
|
+
xml.gitTool "Default"
|
113
|
+
xml.submoduleCfg(:class => "list")
|
114
|
+
xml.relativeTargetDir
|
115
|
+
xml.reference
|
116
|
+
xml.excludedRegions
|
117
|
+
xml.excludedUsers
|
118
|
+
xml.gitConfigName
|
119
|
+
xml.gitConfigEmail
|
120
|
+
xml.skipTag "false"
|
121
|
+
xml.includedRegions
|
122
|
+
xml.scmName
|
123
|
+
}
|
124
|
+
else
|
125
|
+
xml.scm(:class => "hudson.scm.NullSCM")
|
126
|
+
end
|
127
|
+
xml.canRoam "true"
|
128
|
+
xml.disabled "false"
|
129
|
+
xml.blockBuildWhenDownstreamBuilding "#{params[:block_build_when_downstream_building]}"
|
130
|
+
xml.blockBuildWhenUpstreamBuilding "#{params[:block_build_when_upstream_building]}"
|
131
|
+
xml.triggers.vector {
|
132
|
+
xml.send('com.cloudbees.jenkins.GitHubPushTrigger', :plugin => "github@1.4"){
|
133
|
+
xml.spec
|
134
|
+
}
|
135
|
+
xml.send('hudson.triggers.SCMTrigger'){
|
136
|
+
xml.spec "* * * * *"
|
137
|
+
xml.ignorePostCommitHooks 'false'
|
138
|
+
}
|
139
|
+
}
|
140
|
+
xml.concurrentBuild "#{params[:concurrent_build]}"
|
141
|
+
# Shell command stuff
|
142
|
+
xml.builders {
|
143
|
+
if params[:shell_command]
|
144
|
+
xml.send("hudson.tasks.Shell") {
|
145
|
+
xml.command "#{params[:shell_command]}"
|
146
|
+
}
|
147
|
+
end
|
148
|
+
}
|
149
|
+
# Adding Downstream projects
|
150
|
+
xml.publishers {
|
151
|
+
if params[:child_projects]
|
152
|
+
xml.send("hudson.tasks.BuildTrigger") {
|
153
|
+
xml.childProjects"#{params[:child_projects]}"
|
154
|
+
name, ordinal, color = get_threshold_params(params[:child_threshold])
|
155
|
+
xml.threshold {
|
156
|
+
xml.name "#{name}"
|
157
|
+
xml.ordinal "#{ordinal}"
|
158
|
+
xml.color "#{color}"
|
159
|
+
}
|
160
|
+
}
|
161
|
+
end
|
162
|
+
}
|
163
|
+
xml.buildWrappers
|
164
|
+
}
|
165
|
+
}
|
166
|
+
builder.to_xml
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jenkins::Configuration do
|
4
|
+
before do
|
5
|
+
Jenkins::Configuration.any_instance.stub(:script_file).and_return(file('build'))
|
6
|
+
@configuration = Jenkins::Configuration.new(config_file)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#params' do
|
10
|
+
it 'reads shell script file and returns shell content' do
|
11
|
+
params = @configuration.params.first
|
12
|
+
script = File.read(@configuration.jobs.first[:shell_script])
|
13
|
+
expect(params[:shell_command]).to include(script)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
describe JenkinsApi::Client::Job do
|
5
|
+
before do
|
6
|
+
@client = mock
|
7
|
+
@job = JenkinsApi::Client::Job.new(@client)
|
8
|
+
@params = {
|
9
|
+
:name => 'job',
|
10
|
+
:keep_dependencies => true,
|
11
|
+
:block_build_when_downstream_building => true,
|
12
|
+
:block_build_when_upstream_building => true,
|
13
|
+
:concurrent_build => true,
|
14
|
+
:scm_provider => 'git',
|
15
|
+
:scm_url => 'git@github.com:anhkind/jenkins-rails.git',
|
16
|
+
:scm_branch => 'master',
|
17
|
+
:shell_command => "echo 'Hello World'"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#xml_config' do
|
22
|
+
it "returns xml from hash config" do
|
23
|
+
@xml = @job.xml_config(@params)
|
24
|
+
n_xml = Nokogiri::XML(@xml)
|
25
|
+
|
26
|
+
keep_dependencies = n_xml.xpath("//keepDependencies").first.content
|
27
|
+
expect(keep_dependencies).to eq('true')
|
28
|
+
|
29
|
+
block_build_when_downstream_building = n_xml.xpath("//blockBuildWhenDownstreamBuilding").first.content
|
30
|
+
expect(block_build_when_downstream_building).to eq('true')
|
31
|
+
|
32
|
+
block_build_when_upstream_building = n_xml.xpath("//blockBuildWhenUpstreamBuilding").first.content
|
33
|
+
expect(block_build_when_upstream_building).to eq('true')
|
34
|
+
|
35
|
+
concurrent_build = n_xml.xpath("//concurrentBuild").first.content
|
36
|
+
expect(concurrent_build).to eq('true')
|
37
|
+
|
38
|
+
scm_provider = n_xml.xpath("//scm[@class='hudson.plugins.git.GitSCM']").first
|
39
|
+
expect(scm_provider).not_to be_blank
|
40
|
+
|
41
|
+
scm_url = n_xml.xpath("//userRemoteConfigs//url").first.content
|
42
|
+
expect(scm_url).to eq('git@github.com:anhkind/jenkins-rails.git')
|
43
|
+
|
44
|
+
scm_branch = n_xml.xpath("//hudson.plugins.git.BranchSpec/name").first.content
|
45
|
+
expect(scm_branch).to eq('master')
|
46
|
+
|
47
|
+
shell_command = n_xml.xpath("//hudson.tasks.Shell/command").first.content
|
48
|
+
expect(shell_command).to eq("echo 'Hello World'")
|
49
|
+
|
50
|
+
authorization_matrix = n_xml.xpath("//hudson.security.AuthorizationMatrixProperty").first
|
51
|
+
expect(authorization_matrix).not_to be_blank
|
52
|
+
|
53
|
+
github_push_trigger = n_xml.xpath("//com.cloudbees.jenkins.GitHubPushTrigger").first
|
54
|
+
expect(github_push_trigger).not_to be_blank
|
55
|
+
|
56
|
+
scm_trigger = n_xml.xpath("//hudson.triggers.SCMTrigger").first
|
57
|
+
expect(scm_trigger).not_to be_blank
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#fast_create' do
|
62
|
+
it 'creates new job from hash input' do
|
63
|
+
@client.should_receive(:post_config)
|
64
|
+
@job.fast_create(@params)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#fast_configure' do
|
69
|
+
it 'configures a job from hash input' do
|
70
|
+
@client.should_receive(:post_config)
|
71
|
+
@job.fast_configure(@params)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jenkins do
|
4
|
+
describe '.configure' do
|
5
|
+
it 'configures correctly' do
|
6
|
+
if config_with_credential?
|
7
|
+
Jenkins.configure(
|
8
|
+
:config_file => config_file
|
9
|
+
)
|
10
|
+
#check with Jenkin API Client
|
11
|
+
job_name = Jenkins.configuration.jobs.first[:name]
|
12
|
+
expect(Jenkins.client.job.list(job_name)).not_to be_blank
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/jenkins.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
username: <%= ENV['JENKINS_USERNAME'] %>
|
2
|
+
password: <%= ENV['JENKINS_PASSWORD'] %>
|
3
|
+
host: <%= ENV['JENKINS_HOST'] %>
|
4
|
+
jobs:
|
5
|
+
-
|
6
|
+
name: 'Test App'
|
7
|
+
scm_provider: 'git'
|
8
|
+
scm_url: 'git://github.com/apraditya/sampleapp.git'
|
9
|
+
scm_branch: 'master'
|
10
|
+
shell_script: <%= File.join(SPEC_ROOT, 'fixtures', 'files', 'build') %>
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "jenkins-rails"
|
2
|
+
|
3
|
+
SPEC_ROOT = File.join(Jenkins::GEM_ROOT, 'spec')
|
4
|
+
|
5
|
+
Dir[File.join(SPEC_ROOT, "support", "**/*.rb")].each { |f| require f }
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.before(:each) do
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
config.include RSpecHelpers
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RSpecHelpers
|
2
|
+
def file(filename)
|
3
|
+
File.join(SPEC_ROOT, "fixtures", "files", filename)
|
4
|
+
end
|
5
|
+
|
6
|
+
def config_file
|
7
|
+
File.join(SPEC_ROOT, 'jenkins.yml')
|
8
|
+
end
|
9
|
+
|
10
|
+
def config_with_credential?
|
11
|
+
config = YAML.load(ERB.new(File.read(config_file)).result).symbolize_keys
|
12
|
+
config[:username] && config[:password]
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jenkins-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Anh Nguyen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jenkins_api_client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.5.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.5.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.11'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.11'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: builder
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Jenkins integration for Rails
|
79
|
+
email:
|
80
|
+
- anhkind@gmail.com
|
81
|
+
executables:
|
82
|
+
- build
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .travis.yml
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- bin/build
|
93
|
+
- jenkins-rails.gemspec
|
94
|
+
- lib/jenkins-rails.rb
|
95
|
+
- lib/jenkins-rails/configuration.rb
|
96
|
+
- lib/jenkins-rails/ext.rb
|
97
|
+
- lib/jenkins-rails/railtie.rb
|
98
|
+
- lib/jenkins-rails/tasks/jenkins.rake
|
99
|
+
- lib/jenkins-rails/version.rb
|
100
|
+
- spec/fixtures/files/build
|
101
|
+
- spec/jenkins-rails/configuration_spec.rb
|
102
|
+
- spec/jenkins-rails/ext_spec.rb
|
103
|
+
- spec/jenkins-rails_spec.rb
|
104
|
+
- spec/jenkins.yml
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/support/rspec_helpers.rb
|
107
|
+
homepage: ''
|
108
|
+
licenses: []
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.24
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Jenkins integration for Rails
|
131
|
+
test_files:
|
132
|
+
- spec/fixtures/files/build
|
133
|
+
- spec/jenkins-rails/configuration_spec.rb
|
134
|
+
- spec/jenkins-rails/ext_spec.rb
|
135
|
+
- spec/jenkins-rails_spec.rb
|
136
|
+
- spec/jenkins.yml
|
137
|
+
- spec/spec_helper.rb
|
138
|
+
- spec/support/rspec_helpers.rb
|