jenkins-maestrodev 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/Changelog.md +58 -0
  3. data/Gemfile +3 -0
  4. data/README.md +162 -0
  5. data/Rakefile +110 -0
  6. data/bin/jenkins +9 -0
  7. data/cucumber.yml +8 -0
  8. data/features/build_details.feature +44 -0
  9. data/features/configure.feature +36 -0
  10. data/features/default_host.feature +26 -0
  11. data/features/development.feature +14 -0
  12. data/features/listing_jobs.feature +34 -0
  13. data/features/manage_jobs.feature +263 -0
  14. data/features/manage_slave_nodes.feature +83 -0
  15. data/features/step_definitions/common_steps.rb +192 -0
  16. data/features/step_definitions/fixture_project_steps.rb +8 -0
  17. data/features/step_definitions/jenkins_steps.rb +116 -0
  18. data/features/step_definitions/scm_steps.rb +12 -0
  19. data/features/support/common.rb +37 -0
  20. data/features/support/env.rb +19 -0
  21. data/features/support/hooks.rb +16 -0
  22. data/features/support/jenkins_helpers.rb +6 -0
  23. data/features/support/matchers.rb +10 -0
  24. data/fixtures/jenkins/envfile.hpi +0 -0
  25. data/fixtures/jenkins/git.hpi +0 -0
  26. data/fixtures/jenkins/github.hpi +0 -0
  27. data/fixtures/jenkins/greenballs.hpi +0 -0
  28. data/fixtures/jenkins/rake.hpi +0 -0
  29. data/fixtures/jenkins/ruby.hpi +0 -0
  30. data/fixtures/projects/erlang/rebar.config +1 -0
  31. data/fixtures/projects/non-bundler/Rakefile +4 -0
  32. data/fixtures/projects/rails-3/.gitignore +4 -0
  33. data/fixtures/projects/rails-3/Gemfile +30 -0
  34. data/fixtures/projects/rails-3/Gemfile.lock +74 -0
  35. data/fixtures/projects/rails-3/README +256 -0
  36. data/fixtures/projects/rails-3/Rakefile +7 -0
  37. data/fixtures/projects/rails-3/app/controllers/application_controller.rb +3 -0
  38. data/fixtures/projects/rails-3/app/helpers/application_helper.rb +2 -0
  39. data/fixtures/projects/rails-3/app/views/layouts/application.html.erb +14 -0
  40. data/fixtures/projects/rails-3/config.ru +4 -0
  41. data/fixtures/projects/rails-3/config/application.rb +42 -0
  42. data/fixtures/projects/rails-3/config/boot.rb +13 -0
  43. data/fixtures/projects/rails-3/config/database.yml +22 -0
  44. data/fixtures/projects/rails-3/config/environment.rb +5 -0
  45. data/fixtures/projects/rails-3/config/environments/development.rb +26 -0
  46. data/fixtures/projects/rails-3/config/environments/production.rb +49 -0
  47. data/fixtures/projects/rails-3/config/environments/test.rb +35 -0
  48. data/fixtures/projects/rails-3/config/initializers/backtrace_silencers.rb +7 -0
  49. data/fixtures/projects/rails-3/config/initializers/inflections.rb +10 -0
  50. data/fixtures/projects/rails-3/config/initializers/mime_types.rb +5 -0
  51. data/fixtures/projects/rails-3/config/initializers/secret_token.rb +7 -0
  52. data/fixtures/projects/rails-3/config/initializers/session_store.rb +8 -0
  53. data/fixtures/projects/rails-3/config/locales/en.yml +5 -0
  54. data/fixtures/projects/rails-3/config/routes.rb +58 -0
  55. data/fixtures/projects/rails-3/db/seeds.rb +7 -0
  56. data/fixtures/projects/rails-3/doc/README_FOR_APP +2 -0
  57. data/fixtures/projects/rails-3/lib/tasks/.gitkeep +0 -0
  58. data/fixtures/projects/rails-3/public/404.html +26 -0
  59. data/fixtures/projects/rails-3/public/422.html +26 -0
  60. data/fixtures/projects/rails-3/public/500.html +26 -0
  61. data/fixtures/projects/rails-3/public/favicon.ico +0 -0
  62. data/fixtures/projects/rails-3/public/images/rails.png +0 -0
  63. data/fixtures/projects/rails-3/public/index.html +239 -0
  64. data/fixtures/projects/rails-3/public/javascripts/application.js +2 -0
  65. data/fixtures/projects/rails-3/public/javascripts/controls.js +965 -0
  66. data/fixtures/projects/rails-3/public/javascripts/dragdrop.js +974 -0
  67. data/fixtures/projects/rails-3/public/javascripts/effects.js +1123 -0
  68. data/fixtures/projects/rails-3/public/javascripts/prototype.js +6001 -0
  69. data/fixtures/projects/rails-3/public/javascripts/rails.js +175 -0
  70. data/fixtures/projects/rails-3/public/robots.txt +5 -0
  71. data/fixtures/projects/rails-3/public/stylesheets/.gitkeep +0 -0
  72. data/fixtures/projects/rails-3/script/rails +6 -0
  73. data/fixtures/projects/rails-3/test/performance/browsing_test.rb +9 -0
  74. data/fixtures/projects/rails-3/test/test_helper.rb +13 -0
  75. data/fixtures/projects/rails-3/vendor/plugins/.gitkeep +0 -0
  76. data/fixtures/projects/ruby/Gemfile +3 -0
  77. data/fixtures/projects/ruby/Gemfile.lock +10 -0
  78. data/fixtures/projects/ruby/Rakefile +4 -0
  79. data/jenkins.gemspec +34 -0
  80. data/lib/jenkins.rb +6 -0
  81. data/lib/jenkins/api.rb +312 -0
  82. data/lib/jenkins/cli.rb +361 -0
  83. data/lib/jenkins/cli/formatting.rb +53 -0
  84. data/lib/jenkins/config.rb +27 -0
  85. data/lib/jenkins/core_ext/hash.rb +9 -0
  86. data/lib/jenkins/core_ext/object/blank.rb +77 -0
  87. data/lib/jenkins/hudson-cli.jar +0 -0
  88. data/lib/jenkins/job_config_builder.rb +417 -0
  89. data/lib/jenkins/project_scm.rb +22 -0
  90. data/lib/jenkins/remote.rb +11 -0
  91. data/lib/jenkins/version.rb +3 -0
  92. data/spec/api_spec.rb +67 -0
  93. data/spec/fixtures/ec2_global.config.xml +103 -0
  94. data/spec/fixtures/erlang.single.config.xml +59 -0
  95. data/spec/fixtures/rails.multi.config.xml +82 -0
  96. data/spec/fixtures/rails.single.config.triggers.xml +84 -0
  97. data/spec/fixtures/rails.single.config.xml +80 -0
  98. data/spec/fixtures/ruby.multi-ruby-multi-labels.config.xml +84 -0
  99. data/spec/fixtures/ruby.multi.config.xml +77 -0
  100. data/spec/fixtures/ruby.single.config.xml +58 -0
  101. data/spec/fixtures/ruby.user-defined-axis.config.xml +69 -0
  102. data/spec/fixtures/therubyracer.config.xml +77 -0
  103. data/spec/hash_key_cleaner_spec.rb +25 -0
  104. data/spec/job_config_builder_spec.rb +233 -0
  105. data/spec/spec_helper.rb +15 -0
  106. metadata +291 -0
@@ -0,0 +1,26 @@
1
+ Feature: Display default host information
2
+
3
+ Scenario: Display default host information if it is setup
4
+ Given I run local executable "jenkins" with arguments "configure --host localhost --port 3010"
5
+ When I run local executable "jenkins" with arguments "default_host"
6
+ Then I should see exactly
7
+ """
8
+ http://localhost:3010
9
+ """
10
+
11
+ Scenario: Display default secure host information if it is setup
12
+ Given I run local executable "jenkins" with arguments "configure --host localhost --port 3010 --ssl"
13
+ When I run local executable "jenkins" with arguments "default_host"
14
+ Then I should see exactly
15
+ """
16
+ https://localhost:3010
17
+ """
18
+
19
+ Scenario: Display warning if never used Jenkins.rb before
20
+ When I run local executable "jenkins" with arguments "default_host"
21
+ Then I should see exactly
22
+ """
23
+ ERROR: Either use --host or add remote servers.
24
+ """
25
+
26
+
@@ -0,0 +1,14 @@
1
+ Feature: Development processes of jenkins itself (rake tasks)
2
+
3
+ As a Newgem maintainer or contributor
4
+ I want rake tasks to maintain and release the gem
5
+ So that I can spend time on the tests and code, and not excessive time on maintenance processes
6
+
7
+ Scenario: Generate RubyGem
8
+ Given this project is active project folder
9
+ When I invoke task "rake clean" so that I start with nothing
10
+ And I invoke task "rake build"
11
+ Then file with name matching "pkg/jenkins-*.gem" is created
12
+ And file with name matching "jenkins.gemspec" is created
13
+ And the file "jenkins.gemspec" is a valid gemspec
14
+
@@ -0,0 +1,34 @@
1
+ Feature: Listing jobs
2
+ I want to see the status of jobs on servers I'm interested in
3
+
4
+ Scenario: List jobs on a non-existent server (jenkins list)
5
+ When I run local executable "jenkins" with arguments "list --host localhost --port 9999"
6
+ Then I should see exactly
7
+ """
8
+ No connection available to the server.
9
+ """
10
+
11
+ @jenkins-server
12
+ Scenario: List jobs on a server with no jobs (jenkins list)
13
+ Given I have a Jenkins server running
14
+ And the Jenkins server has no current jobs
15
+ When I run local executable "jenkins" with arguments "list --host localhost --port 3010"
16
+ Then I should see exactly
17
+ """
18
+ http://localhost:3010: no jobs
19
+ """
20
+
21
+ @jenkins-server
22
+ Scenario: List jobs on a server with jobs (jenkins list)
23
+ Given I have a Jenkins server running
24
+ And the Jenkins server has no current jobs
25
+ And I am in the "ruby" project folder
26
+ And the project uses "git" scm
27
+ When I run local executable "jenkins" with arguments "create . --host localhost --port 3010"
28
+ When I run local executable "jenkins" with arguments "list"
29
+ Then I should see exactly
30
+ """
31
+ http://localhost:3010:
32
+ * ruby
33
+
34
+ """
@@ -0,0 +1,263 @@
1
+ @jenkins-server
2
+ Feature: Create and manage jobs
3
+ In order to reduce cost of getting a new project up onto Jenkins
4
+ As a project developer
5
+ I want to add a new project to Jenkins as a job
6
+
7
+ Background:
8
+ Given I have a Jenkins server running
9
+ And the Jenkins server has no current jobs
10
+
11
+ Scenario: Setup jenkins job for git scm (jenkins create)
12
+ Given I am in the "ruby" project folder
13
+ And the project uses "git" scm
14
+ When I run local executable "jenkins" with arguments "create . --host localhost --port 3010"
15
+ Then I should see exactly
16
+ """
17
+ Added ruby project 'ruby' to Jenkins.
18
+ Triggering initial build...
19
+ Trigger additional builds via:
20
+ URL: http://localhost:3010/job/ruby/build
21
+ CLI: jenkins build ruby
22
+ """
23
+ When I run local executable "jenkins" with arguments "list --host localhost --port 3010"
24
+ Then I should see "ruby"
25
+
26
+ Scenario: Create job via $JENKINS_HOST and $JENKINS_PORT (jenkins create)
27
+ Given I am in the "ruby" project folder
28
+ And the project uses "git" scm
29
+ And env variable $JENKINS_HOST set to "localhost"
30
+ And env variable $JENKINS_PORT set to "3010"
31
+ When I run local executable "jenkins" with arguments "create ."
32
+ Then I should see "http://localhost:3010/job/ruby/build"
33
+ When I run local executable "jenkins" with arguments "list"
34
+ Then I should see "ruby"
35
+
36
+ Scenario: Don't trigger initial job build (jenkins create --no-build)
37
+ Given I am in the "ruby" project folder
38
+ And the project uses "git" scm
39
+ When I run local executable "jenkins" with arguments "create . --no-build --host localhost --port 3010"
40
+ Then I should see exactly
41
+ """
42
+ Added ruby project 'ruby' to Jenkins.
43
+ Trigger builds via:
44
+ URL: http://localhost:3010/job/ruby/build
45
+ CLI: jenkins build ruby
46
+ """
47
+
48
+ Scenario: Setup jenkins job with explicit scm url/branches (jenkins create --scm URI --scm-branches='master,other')
49
+ Given I am in the "ruby" project folder
50
+ And the project uses "git" scm
51
+ When I run local executable "jenkins" with arguments "create . --scm git://localhost/myapp.git --scm-branches 'master,other' --host localhost --port 3010"
52
+ Then I should see "Added ruby project 'ruby' to Jenkins."
53
+ And the job "ruby" config "scm" should be:
54
+ """
55
+ <scm class="hudson.plugins.git.GitSCM">
56
+ <configVersion>1</configVersion>
57
+ <remoteRepositories>
58
+ <org.spearce.jgit.transport.RemoteConfig>
59
+ <string>origin</string>
60
+ <int>5</int>
61
+ <string>fetch</string>
62
+ <string>+refs/heads/*:refs/remotes/origin/*</string>
63
+ <string>receivepack</string>
64
+ <string>git-upload-pack</string>
65
+ <string>uploadpack</string>
66
+ <string>git-upload-pack</string>
67
+ <string>url</string>
68
+ <string>git://localhost/myapp.git</string>
69
+ <string>tagopt</string>
70
+ <string></string>
71
+ </org.spearce.jgit.transport.RemoteConfig>
72
+ </remoteRepositories>
73
+ <branches>
74
+ <hudson.plugins.git.BranchSpec>
75
+ <name>master</name>
76
+ </hudson.plugins.git.BranchSpec>
77
+ <hudson.plugins.git.BranchSpec>
78
+ <name>other</name>
79
+ </hudson.plugins.git.BranchSpec>
80
+ </branches>
81
+ <localBranch></localBranch>
82
+ <mergeOptions />
83
+ <recursiveSubmodules>false</recursiveSubmodules>
84
+ <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
85
+ <authorOrCommitter>false</authorOrCommitter>
86
+ <clean>false</clean>
87
+ <wipeOutWorkspace>false</wipeOutWorkspace>
88
+ <pruneBranches>false</pruneBranches>
89
+ <buildChooser class="hudson.plugins.git.util.DefaultBuildChooser" />
90
+ <gitTool>Default</gitTool>
91
+ <submoduleCfg class="list" />
92
+ <relativeTargetDir></relativeTargetDir>
93
+ <excludedRegions></excludedRegions>
94
+ <excludedUsers></excludedUsers>
95
+ </scm>
96
+ """
97
+
98
+ Scenario: Update the SCM configuration of an existing jenkins job (jenkins update . --scm URI --scm-branches='master')
99
+ Given I am in the "ruby" project folder
100
+ And the project uses "git" scm
101
+ And I run local executable "jenkins" with arguments "create . --scm git://localhost/myapp.git --scm-branches 'master,other' --host localhost --port 3010"
102
+ Then I should see "Added ruby project 'ruby' to Jenkins."
103
+ And I run local executable "jenkins" with arguments "update . --scm git://localhost/myapp_new.git --scm-branches 'master' --host localhost --port 3010"
104
+ Then I should see "Updated ruby project 'ruby'."
105
+ And the job "ruby" config "scm" should be:
106
+ """
107
+ <scm class="hudson.plugins.git.GitSCM">
108
+ <configVersion>1</configVersion>
109
+ <remoteRepositories>
110
+ <org.spearce.jgit.transport.RemoteConfig>
111
+ <string>origin</string>
112
+ <int>5</int>
113
+ <string>fetch</string>
114
+ <string>+refs/heads/*:refs/remotes/origin/*</string>
115
+ <string>receivepack</string>
116
+ <string>git-upload-pack</string>
117
+ <string>uploadpack</string>
118
+ <string>git-upload-pack</string>
119
+ <string>url</string>
120
+ <string>git://localhost/myapp_new.git</string>
121
+ <string>tagopt</string>
122
+ <string />
123
+ </org.spearce.jgit.transport.RemoteConfig>
124
+ </remoteRepositories>
125
+ <branches>
126
+ <hudson.plugins.git.BranchSpec>
127
+ <name>master</name>
128
+ </hudson.plugins.git.BranchSpec>
129
+ </branches>
130
+ <localBranch />
131
+ <mergeOptions />
132
+ <recursiveSubmodules>false</recursiveSubmodules>
133
+ <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
134
+ <authorOrCommitter>false</authorOrCommitter>
135
+ <clean>false</clean>
136
+ <wipeOutWorkspace>false</wipeOutWorkspace>
137
+ <buildChooser class="hudson.plugins.git.util.DefaultBuildChooser" />
138
+ <gitTool>Default</gitTool>
139
+ <submoduleCfg class="list" />
140
+ <relativeTargetDir />
141
+ <excludedRegions />
142
+ <excludedUsers />
143
+ </scm>
144
+ """
145
+
146
+ Scenario: Setup jenkins job with multiple rubies (jenkins create --rubies '1.8.7,rbx-head,jruby')
147
+ Given I am in the "ruby" project folder
148
+ And the project uses "git" scm
149
+ When I run local executable "jenkins" with arguments "create . --rubies '1.8.7,rbx-head,jruby' --host localhost --port 3010"
150
+ Then I should see "Added ruby project 'ruby' to Jenkins."
151
+ And the job "ruby" config "axes" should be:
152
+ """
153
+ <axes>
154
+ <hudson.matrix.TextAxis>
155
+ <name>RUBY_VERSION</name>
156
+ <values>
157
+ <string>1.8.7</string>
158
+ <string>rbx-head</string>
159
+ <string>jruby</string>
160
+ </values>
161
+ </hudson.matrix.TextAxis>
162
+ </axes>
163
+ """
164
+
165
+ Scenario: Setup jenkins job with multiple rubies and multiple nodes (jenkins create --rubies.. --node_labels..)
166
+ Given I am in the "ruby" project folder
167
+ And the project uses "git" scm
168
+ When I run local executable "jenkins" with arguments "create . --rubies '1.8.7,rbx-head,jruby' --node-labels '1.8.7,ubuntu' --host localhost --port 3010"
169
+ Then I should see "Added ruby project 'ruby' to Jenkins."
170
+ And the job "ruby" config "axes" should be:
171
+ """
172
+ <axes>
173
+ <hudson.matrix.TextAxis>
174
+ <name>RUBY_VERSION</name>
175
+ <values>
176
+ <string>1.8.7</string>
177
+ <string>rbx-head</string>
178
+ <string>jruby</string>
179
+ </values>
180
+ </hudson.matrix.TextAxis>
181
+ <hudson.matrix.LabelAxis>
182
+ <name>label</name>
183
+ <values>
184
+ <string>1.8.7</string>
185
+ <string>ubuntu</string>
186
+ </values>
187
+ </hudson.matrix.LabelAxis>
188
+ </axes>
189
+ """
190
+
191
+ Scenario: Setup jenkins job for a specific node label (jenkins create --assigned_node)
192
+ Given I am in the "ruby" project folder
193
+ And the project uses "git" scm
194
+ When I run local executable "jenkins" with arguments "create . --assigned_node my_node --host localhost --port 3010"
195
+ Then I should see "Added ruby project 'ruby' to Jenkins."
196
+
197
+ Scenario: Select 'rails3' project type (jenkins create --template rails3)
198
+ Given I am in the "rails-3" project folder
199
+ And the project uses "git" scm
200
+ When I run local executable "jenkins" with arguments "create . --template rails3 --host localhost --port 3010"
201
+ Then I should see "Added rails3 project 'rails-3' to Jenkins."
202
+
203
+ Scenario: Select 'erlang' project type (jenkins create --template erlang)
204
+ Given I am in the "erlang" project folder
205
+ And the project uses "git" scm
206
+ When I run local executable "jenkins" with arguments "create . --template erlang --host localhost --port 3010"
207
+ Then I should see "Added erlang project 'erlang' to Jenkins."
208
+
209
+ Scenario: Create job without default steps (jenkins create --no-template)
210
+ Given I am in the "non-bundler" project folder
211
+ And the project uses "git" scm
212
+ When I run local executable "jenkins" with arguments "create . --no-template --host localhost --port 3010"
213
+ Then I should see "Added project 'non-bundler' to Jenkins."
214
+ And the job "non-bundler" config "builders" should be:
215
+ """
216
+ <builders>
217
+ <hudson.tasks.Shell>
218
+ <command>echo &quot;THERE ARE NO STEPS! Except this one...&quot;</command>
219
+ </hudson.tasks.Shell>
220
+ </builders>
221
+ """
222
+
223
+ Scenario: Reject projects that don't use bundler (jenkins create)
224
+ Given I am in the "non-bundler" project folder
225
+ And the project uses "git" scm
226
+ When I run local executable "jenkins" with arguments "create . --host localhost --port 3010"
227
+ Then I should see "Ruby/Rails projects without a Gemfile are currently unsupported."
228
+
229
+ Scenario: Attempt to create project without scm (jenkins create)
230
+ Given I am in the "ruby" project folder
231
+ When I run local executable "jenkins" with arguments "create . --host localhost --port 3010"
232
+ Then I should see "Cannot determine project SCM. Currently supported:"
233
+
234
+ Scenario: Recreate a job (jenkins create --override)
235
+ Given I am in the "ruby" project folder
236
+ When I create a job
237
+ Then I should see "Added ruby project 'ruby' to Jenkins."
238
+ When I recreate a job
239
+ Then I should see "Added ruby project 'ruby' to Jenkins."
240
+
241
+ Scenario: Trigger a job build (jenkins build)
242
+ Given I am in the "ruby" project folder
243
+ When I create a job
244
+ When I run local executable "jenkins" with arguments "build"
245
+ Then I should see "Build for 'ruby' running now..."
246
+
247
+ Scenario: Trigger a job build on invaild project (jenkins build)
248
+ Given I am in the "ruby" project folder
249
+ When I run local executable "jenkins" with arguments "build . --host localhost --port 3010"
250
+ Then I should see "ERROR: No job 'ruby' on server."
251
+
252
+ Scenario: Remove a job (jenkins remove)
253
+ Given I am in the "ruby" project folder
254
+ When I create a job
255
+ Then I should see "Added ruby project 'ruby' to Jenkins."
256
+ When I run local executable "jenkins" with arguments "remove ."
257
+ Then I should see "Removed project 'ruby' from Jenkins."
258
+
259
+ Scenario: Remove a job that doesn't exist gives error (jenkins remove)
260
+ Given I am in the "ruby" project folder
261
+ When I run local executable "jenkins" with arguments "remove . --host localhost --port 3010"
262
+ Then I should see "ERROR: Failed to delete project 'ruby'."
263
+
@@ -0,0 +1,83 @@
1
+ @jenkins-server
2
+ Feature: Adding slave nodes
3
+ In order to have different environments for different projects
4
+ As a developer
5
+ I want to add new slave nodes to my Jenkins instance
6
+
7
+ Background:
8
+ Given I have a Jenkins server running
9
+ And the Jenkins server has no slaves
10
+ When I run local executable "jenkins" with arguments "nodes --host localhost --port 3010"
11
+ Then I should see exactly
12
+ """
13
+ master
14
+ """
15
+
16
+ Scenario: Add slave via API (jenkins nodes)
17
+ When I create a new node with the following options on "http://localhost:3010":
18
+ | name | Slave 1 |
19
+ | label | app1 app2 app3 |
20
+ | slave_host | foo1.bar.com |
21
+ | slave_user | jenkins |
22
+ When I run local executable "jenkins" with arguments "nodes"
23
+ Then I should see exactly
24
+ """
25
+ master
26
+ Slave 1
27
+ """
28
+
29
+ Scenario: Add slave via CLI with name defaulted to URL (jenkins add_node)
30
+ When I run local executable "jenkins" with arguments "add_node foo1.bar.com --slave-user deploy --labels 'app1,app2'"
31
+ Then I should see exactly
32
+ """
33
+ Added slave node 'foo1.bar.com' to foo1.bar.com
34
+ """
35
+ When I run local executable "jenkins" with arguments "add_node foo1.bar.com --slave-user deploy --labels 'app1,app2'"
36
+ Then I should see exactly
37
+ """
38
+ Slave called 'foo1.bar.com' already exists
39
+ ERROR: Failed to add slave node foo1.bar.com
40
+ """
41
+ When I run local executable "jenkins" with arguments "nodes"
42
+ Then I should see exactly
43
+ """
44
+ master
45
+ foo1.bar.com
46
+ """
47
+
48
+ @wip
49
+ Scenario: Add a local Vagrant/VirtualBox VM as a slave (jenkins add_node --vagrant)
50
+ Given I am in the "rails-3" project folder
51
+ When I run local executable "jenkins" with arguments "add_node localhost --name rails-3 --vagrant --labels 'app1,app2'"
52
+ Then I should see exactly
53
+ """
54
+ Added slave node 'rails-3' to localhost
55
+ """
56
+ When I run local executable "jenkins" with arguments "nodes"
57
+ Then I should see exactly
58
+ """
59
+ master
60
+ rails-3
61
+ """
62
+ And the Jenkins config "slaves" should be:
63
+ """
64
+ <slaves>
65
+ <slave>
66
+ <name>rails-3</name>
67
+ <description>Automatically created by Jenkins.rb</description>
68
+ <remoteFS>/vagrant/tmp/jenkins-slave/</remoteFS>
69
+ <numExecutors>2</numExecutors>
70
+ <mode>EXCLUSIVE</mode>
71
+ <retentionStrategy class="hudson.slaves.RetentionStrategy$Always" />
72
+ <launcher class="hudson.plugins.sshslaves.SSHLauncher">
73
+ <host>localhost</host>
74
+ <port>2222</port>
75
+ <username>vagrant</username>
76
+ <password>rvDV+OTiBj3UtK5p7sl62Q==</password>
77
+ <privatekey>/Library/Ruby/Gems/1.8/gems/vagrant-0.6.7/keys/vagrant</privatekey>
78
+ </launcher>
79
+ <label>app1 app2</label>
80
+ <nodeProperties />
81
+ </slave>
82
+ </slaves>
83
+ """
@@ -0,0 +1,192 @@
1
+
2
+ Given /^this project is active project folder/ do
3
+ @active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
4
+ end
5
+
6
+ Given /^env variable \$([\w_]+) set to( project path|) "(.*)"/ do |env_var, path, value|
7
+ in_project_folder {
8
+ value = File.expand_path(value)
9
+ } unless path.empty?
10
+ ENV[env_var] = value
11
+ end
12
+
13
+ Given /"(.*)" folder is deleted/ do |folder|
14
+ in_project_folder { FileUtils.rm_rf folder }
15
+ end
16
+
17
+ When /^I invoke "(.*)" generator with arguments "(.*)"$/ do |generator, arguments|
18
+ @stdout = StringIO.new
19
+ in_project_folder do
20
+ if Object.const_defined?("APP_ROOT")
21
+ APP_ROOT.replace(FileUtils.pwd)
22
+ else
23
+ APP_ROOT = FileUtils.pwd
24
+ end
25
+ run_generator(generator, arguments.split(' '), SOURCES, :stdout => @stdout)
26
+ end
27
+ File.open(File.join(@tmp_root, "generator.out"), "w") do |f|
28
+ @stdout.rewind
29
+ f << @stdout.read
30
+ end
31
+ end
32
+
33
+ When /^I run executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
34
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
35
+ in_project_folder do
36
+ system "#{executable.inspect} #{arguments} > #{@stdout.inspect} 2> #{@stdout.inspect}"
37
+ end
38
+ end
39
+
40
+ When /^I run project executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
41
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
42
+ in_project_folder do
43
+ system "ruby #{executable.inspect} #{arguments} > #{@stdout.inspect} 2> #{@stdout.inspect}"
44
+ end
45
+ end
46
+
47
+ When /^I run local executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
48
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
49
+ executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
50
+ in_project_folder do
51
+ system "ruby #{executable.inspect} #{arguments} > #{@stdout.inspect} 2> #{@stdout.inspect}"
52
+ end
53
+ end
54
+
55
+ When /^I invoke task "rake (.*)"/ do |task|
56
+ @stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
57
+ in_project_folder do
58
+ system "rake #{task} --trace > #{@stdout.inspect} 2> #{@stdout.inspect}"
59
+ end
60
+ end
61
+
62
+ Then /^folder "(.*)" (is|is not) created/ do |folder, is|
63
+ in_project_folder do
64
+ File.exists?(folder).should(is == 'is' ? be_true : be_false)
65
+ end
66
+ end
67
+
68
+ Then /^file "(.*)" (is|is not) created/ do |file, is|
69
+ in_project_folder do
70
+ File.exists?(file).should(is == 'is' ? be_true : be_false)
71
+ end
72
+ end
73
+
74
+ Then /^file with name matching "(.*)" is created/ do |pattern|
75
+ in_project_folder do
76
+ Dir[pattern].should_not be_empty
77
+ end
78
+ end
79
+
80
+ Then /^file "(.*)" contents (does|does not) match \/(.*)\// do |file, does, regex|
81
+ in_project_folder do
82
+ actual_output = File.read(file)
83
+ (does == 'does') ?
84
+ actual_output.should(match(/#{regex}/)) :
85
+ actual_output.should_not(match(/#{regex}/))
86
+ end
87
+ end
88
+
89
+ Then /gem file "(.*)" and generated file "(.*)" should be the same/ do |gem_file, project_file|
90
+ File.exists?(gem_file).should be_true
91
+ File.exists?(project_file).should be_true
92
+ gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
93
+ project_file_contents = File.read(File.join(@active_project_folder, project_file))
94
+ project_file_contents.should == gem_file_contents
95
+ end
96
+
97
+ Then /^(does|does not) invoke generator "(.*)"$/ do |does_invoke, generator|
98
+ actual_output = get_command_output
99
+ does_invoke == "does" ?
100
+ actual_output.should(match(/dependency\s+#{generator}/)) :
101
+ actual_output.should_not(match(/dependency\s+#{generator}/))
102
+ end
103
+
104
+ Then /help options "(.*)" and "(.*)" are displayed/ do |opt1, opt2|
105
+ actual_output = get_command_output
106
+ actual_output.should match(/#{opt1}/)
107
+ actual_output.should match(/#{opt2}/)
108
+ end
109
+
110
+ Then /^I should see "([^\"]*)"$/ do |text|
111
+ actual_output = get_command_output
112
+ actual_output.should contain(text)
113
+ end
114
+
115
+ Then /^I should not see "([^\"]*)"$/ do |text|
116
+ actual_output =
117
+ actual_output.should_not contain(text)
118
+ end
119
+
120
+ Then /^I should see$/ do |text|
121
+ actual_output = get_command_output
122
+ actual_output.should contain(text)
123
+ end
124
+
125
+ Then /^I should not see$/ do |text|
126
+ actual_output = get_command_output
127
+ actual_output.should_not contain(text)
128
+ end
129
+
130
+ Then /^I should see exactly$/ do |text|
131
+ actual_output = get_command_output
132
+ actual_output.should == text
133
+ end
134
+
135
+ Then /^I should see all (\d+) tests pass/ do |expected_test_count|
136
+ expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
137
+ actual_output = get_command_output
138
+ actual_output.should match(expected)
139
+ end
140
+
141
+ Then /^I should see all (\d+) examples pass/ do |expected_test_count|
142
+ expected = %r{^#{expected_test_count} examples?, 0 failures}
143
+ actual_output = get_command_output
144
+ actual_output.should match(expected)
145
+ end
146
+
147
+ Then /^yaml file "(.*)" contains (\{.*\})/ do |file, yaml|
148
+ in_project_folder do
149
+ yaml = eval yaml
150
+ YAML.load(File.read(file)).should == yaml
151
+ end
152
+ end
153
+
154
+ Then /^Rakefile can display tasks successfully/ do
155
+ @stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
156
+ in_project_folder do
157
+ system "rake -T > #{@stdout.inspect} 2> #{@stdout.inspect}"
158
+ end
159
+ actual_output = get_command_output
160
+ actual_output.should match(/^rake\s+\w+\s+#\s.*/)
161
+ end
162
+
163
+ Then /^task "rake (.*)" is executed successfully/ do |task|
164
+ @stdout.should_not be_nil
165
+ actual_output = get_command_output
166
+ actual_output.should_not match(/^Don't know how to build task '#{task}'/)
167
+ actual_output.should_not match(/Error/i)
168
+ end
169
+
170
+ Then /^gem spec key "(.*)" contains \/(.*)\// do |key, regex|
171
+ in_project_folder do
172
+ gem_file = Dir["pkg/*.gem"].first
173
+ gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
174
+ spec_value = gem_spec.send(key.to_sym)
175
+ spec_value.to_s.should match(/#{regex}/)
176
+ end
177
+ end
178
+
179
+ Then /^the file "([^\"]*)" is a valid gemspec$/ do |filename|
180
+ spec = eval(File.read(filename))
181
+ spec.validate
182
+ end
183
+
184
+ When /^I create a new node with the following options on "http:\/\/(.+?):(\d+)":$/ do |host, port, table|
185
+ options = table.raw.inject({}) do |options, (key, value)|
186
+ options[(key.to_sym rescue key) || key] = value
187
+ options
188
+ end
189
+
190
+ Jenkins::Api.setup_base_url(:host => host, :port => port.to_i)
191
+ Jenkins::Api.add_node(options)
192
+ end