jenkins_pipeline_builder 0.4.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02baf3de6c0875361f96889ca4b97d2416279b33
4
- data.tar.gz: 6f1c55c53d76b25bcae5903cb8e9cd881163fb78
3
+ metadata.gz: dd3fbe192beffd805980b40fc49e45a17fc91573
4
+ data.tar.gz: 985c10461b9cda3e85736c37a448072d1c360b11
5
5
  SHA512:
6
- metadata.gz: 5413a1ec062cc1b373decb46b4b3ba1b86aaee0b8ed24c26a00185b81ff165a9a5929fdd3faa5c0e72d46492e0e9c81137a555300247f3f22c9d8c055985ac9f
7
- data.tar.gz: c75e91326db794c6a295ba3d720ebfbfb6928c20f2ce2d76650cbbe53b8600714c5233c72208e7580eb8b4efd3ee64961b3080f34b77dffc614aa5400fb5fd14
6
+ metadata.gz: 9bcc9b579331bddee28a89bfa86e8a0f312dc071ae3e38b31c213d932f6b8744a44bc1dae8381fa552ea166c3a4eb661e22cc5d1e526375812898d9889246062
7
+ data.tar.gz: d52753724255e12b3662c441278d69a1423095d5661a415577f8578630a5c162c3934f0b8115cfaa657c77d094dc67c524eb4bd4deebb7dadd7a645cd31e6fc3
data/README.md CHANGED
@@ -145,6 +145,21 @@ Here's a high level overview of what's available:
145
145
  goals: -B clean
146
146
  rootPom: path_to_pom
147
147
  mavenName: maven-name # Optional
148
+ - remote_job:
149
+ server: 'Name of Server' # Name of the Remote Jenkins Server
150
+ job_name: name_of_remote_build
151
+ blocking: true # Block current job until remote job finishes
152
+ polling_interval: 10 # Optional, number of seconds between polls, defaults to 10
153
+ continue_on_remote_failure: false
154
+ parameters: # Optional, if both are specified only the file is used
155
+ file: 'foo.prop'
156
+ content: |
157
+ VAR1 = value_1
158
+ VAR2 = value_2
159
+ credentials: # Optional, if you want to override the server credentials
160
+ type: api_token or none
161
+ username: name_of_user
162
+ api_token: APITOKEN
148
163
  wrappers:
149
164
  - timestamp: true
150
165
  - ansicolor: true
@@ -204,6 +219,9 @@ Here's a high level overview of what's available:
204
219
  - git_push: true
205
220
  - scm_polling: 'H/5 * * * *'
206
221
  - periodic_build: 'H/15 * * * *'
222
+ - upstream: # Trigger this build after another build has completed
223
+ projects: project-name-here
224
+ status: failed, unstable, stable # Optional, stable by default
207
225
  build_flow: |
208
226
  guard {
209
227
  build("job_name1", param1: params["param1"]);
@@ -71,5 +71,48 @@ module JenkinsPipelineBuilder
71
71
  }
72
72
  }
73
73
  end
74
+
75
+ def self.start_remote_job(params, xml)
76
+ parameters = params[:parameters][:content].split("\n") if params[:parameters] && params[:parameters][:content]
77
+ xml.send('org.jenkinsci.plugins.ParameterizedRemoteTrigger.RemoteBuildConfiguration', 'plugin'=>'Parameterized-Remote-Trigger'){
78
+ xml.remoteJenkinsName params[:server]
79
+ xml.job params[:job_name]
80
+ xml.shouldNotFailBuild params[:continue_on_remote_failure] if params[:continue_on_remote_failure]
81
+ xml.pollInterval params[:polling_interval] if params[:polling_interval]
82
+ xml.blockBuildUntilComplete params[:blocking] if params[:blocking]
83
+ xml.token
84
+ if params[:parameters] && params[:parameters][:content]
85
+ xml.parameters parameters.join("\n")
86
+ xml.parameterList{
87
+ parameters.each do |p|
88
+ xml.string p
89
+ end
90
+ }
91
+ elsif params[:parameters] && params[:parameters][:file]
92
+ xml.loadParamsFromFile 'true'
93
+ xml.parameterFile params[:parameters][:file]
94
+ else
95
+ xml.parameters
96
+ xml.parameterList{
97
+ xml.string
98
+ }
99
+ end
100
+ if params[:credentials] && params[:credentials][:type]
101
+ xml.overrideAuth 'true'
102
+ xml.auth{
103
+ xml.send('org.jenkinsci.plugins.ParameterizedRemoteTrigger.Auth'){
104
+ if params[:credentials][:type]=="api_token"
105
+ xml.authType 'apiToken'
106
+ xml.username params[:credentials][:username]
107
+ xml.API__TOKEN params[:credentials][:api_token]
108
+ else
109
+ xml.authType 'none'
110
+ end
111
+ }
112
+ }
113
+ end
114
+ }
115
+ end
116
+
74
117
  end
75
118
  end
@@ -32,8 +32,8 @@ module JenkinsPipelineBuilder
32
32
  end
33
33
 
34
34
  desc 'bootstrap Path', 'Generates pipeline from folder or a file'
35
- def bootstrap(path)
36
- Helper.setup(parent_options).bootstrap(path)
35
+ def bootstrap(path, project_name = nil)
36
+ Helper.setup(parent_options).bootstrap(path, project_name)
37
37
  end
38
38
  end
39
39
  end
@@ -57,7 +57,8 @@ module JenkinsPipelineBuilder
57
57
  multi_job: Builders.method(:build_multijob),
58
58
  inject_vars_file: Builders.method(:build_environment_vars_injector),
59
59
  shell_command: Builders.method(:build_shell_command),
60
- maven3: Builders.method(:build_maven3)
60
+ maven3: Builders.method(:build_maven3),
61
+ remote_job: Builders.method(:start_remote_job)
61
62
  },
62
63
  method:
63
64
  lambda { |registry, params, n_xml| @module_registry.run_registry_on_path('//builders', registry, params, n_xml) }
@@ -93,7 +94,8 @@ module JenkinsPipelineBuilder
93
94
  registry: {
94
95
  git_push: Triggers.method(:enable_git_push),
95
96
  scm_polling: Triggers.method(:enable_scm_polling),
96
- periodic_build: Triggers.method(:enable_periodic_build)
97
+ periodic_build: Triggers.method(:enable_periodic_build),
98
+ upstream: Triggers.method(:enable_upstream_check)
97
99
  },
98
100
  method:
99
101
  lambda { |registry, params, n_xml| @module_registry.run_registry_on_path('//triggers', registry, params, n_xml) }
@@ -240,7 +242,7 @@ module JenkinsPipelineBuilder
240
242
  return result
241
243
  end
242
244
 
243
- def bootstrap(path)
245
+ def bootstrap(path, project_name)
244
246
  @logger.info "Bootstrapping pipeline from path #{path}"
245
247
  load_collection_from_path(path)
246
248
 
@@ -259,32 +261,34 @@ module JenkinsPipelineBuilder
259
261
  else
260
262
  projects.each do |project|
261
263
  success, payload = resolve_project(project)
262
- if success
263
- puts 'successfully resolved project'
264
- compiled_project = payload
265
- else
266
- puts payload
267
- return false
268
- end
264
+ if payload[:value][:name] == project_name || project_name == nil # If we specify a project name, only use that project
265
+ if success
266
+ puts 'successfully resolved project'
267
+ compiled_project = payload
268
+ else
269
+ puts payload
270
+ return false
271
+ end
269
272
 
270
- if compiled_project[:value][:jobs]
271
- compiled_project[:value][:jobs].each do |i|
272
- puts "Processing #{i}"
273
- job = i[:result]
274
- fail "Result is empty for #{i}" if job.nil?
275
- success, payload = compile_job_to_xml(job)
276
- if success
277
- create_or_update(job, payload)
278
- else
279
- errors[job[:name]] = payload
273
+ if compiled_project[:value][:jobs]
274
+ compiled_project[:value][:jobs].each do |i|
275
+ puts "Processing #{i}"
276
+ job = i[:result]
277
+ fail "Result is empty for #{i}" if job.nil?
278
+ success, payload = compile_job_to_xml(job)
279
+ if success
280
+ create_or_update(job, payload)
281
+ else
282
+ errors[job[:name]] = payload
283
+ end
280
284
  end
281
285
  end
282
- end
283
286
 
284
- if compiled_project[:value][:views]
285
- compiled_project[:value][:views].each do |v|
286
- _view = v[:result]
287
- view.create(_view)
287
+ if compiled_project[:value][:views]
288
+ compiled_project[:value][:views].each do |v|
289
+ _view = v[:result]
290
+ view.create(_view)
291
+ end
288
292
  end
289
293
  end
290
294
  end
@@ -41,5 +41,32 @@ module JenkinsPipelineBuilder
41
41
  }
42
42
  end
43
43
 
44
+ def self.enable_upstream_check(params, xml)
45
+ case params[:status]
46
+ when "unstable"
47
+ name = "UNSTABLE"
48
+ ordinal = "1"
49
+ color = "yellow"
50
+ when "failed"
51
+ name = "FAILURE"
52
+ ordinal = "2"
53
+ color = "RED"
54
+ else
55
+ name = "SUCCESS"
56
+ ordinal = "0"
57
+ color = "BLUE"
58
+ end
59
+ xml.send('jenkins.triggers.ReverseBuildTrigger') {
60
+ xml.spec
61
+ xml.upstreamProjects params[:projects]
62
+ xml.send('threshold'){
63
+ xml.name name
64
+ xml.ordinal ordinal
65
+ xml.color color
66
+ xml.completeBuild true
67
+ }
68
+ }
69
+ end
70
+
44
71
  end
45
72
  end
@@ -21,5 +21,5 @@
21
21
  #
22
22
 
23
23
  module JenkinsPipelineBuilder
24
- VERSION = "0.4.0"
24
+ VERSION = "0.4.2"
25
25
  end
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project>
3
+ <actions/>
4
+ <description/>
5
+ <keepDependencies>false</keepDependencies>
6
+ <properties/>
7
+ <scm class="hudson.scm.NullSCM"/>
8
+ <canRoam>true</canRoam>
9
+ <disabled>false</disabled>
10
+ <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
11
+ <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
12
+ <triggers class="vector"/>
13
+ <concurrentBuild>false</concurrentBuild>
14
+ <builders><org.jenkinsci.plugins.ParameterizedRemoteTrigger.RemoteBuildConfiguration plugin="Parameterized-Remote-Trigger"><remoteJenkinsName>Server2</remoteJenkinsName><job>name_of_remote_build</job><pollInterval>10</pollInterval><blockBuildUntilComplete>true</blockBuildUntilComplete><token/><parameters>VAR1 = value_1
15
+ VAR2 = value_2</parameters><parameterList><string>VAR1 = value_1</string><string>VAR2 = value_2</string></parameterList><overrideAuth>true</overrideAuth><auth><org.jenkinsci.plugins.ParameterizedRemoteTrigger.Auth><authType>apiToken</authType><username>user_name_here</username><API__TOKEN>RAWR123ROVING</API__TOKEN></org.jenkinsci.plugins.ParameterizedRemoteTrigger.Auth></auth></org.jenkinsci.plugins.ParameterizedRemoteTrigger.RemoteBuildConfiguration></builders>
16
+ <publishers/>
17
+ <buildWrappers/>
18
+ </project>
@@ -0,0 +1,19 @@
1
+ - job_template:
2
+ name: remote-job
3
+ job_type: free_style
4
+ builders:
5
+ - remote_job:
6
+ server: 'Server2'
7
+ job_name: name_of_remote_build
8
+ blocking: true
9
+ polling_interval: 10
10
+ continue_on_remote_failure: false
11
+ parameters:
12
+ file: 'foo.prop'
13
+ content: |
14
+ VAR1 = value_1
15
+ VAR2 = value_2
16
+ credentials:
17
+ type: api_token
18
+ username: user_name_here
19
+ api_token: RAWR123ROVING
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project>
3
+ <actions/>
4
+ <description/>
5
+ <keepDependencies>false</keepDependencies>
6
+ <properties/>
7
+ <scm class="hudson.scm.NullSCM"/>
8
+ <canRoam>true</canRoam>
9
+ <disabled>false</disabled>
10
+ <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
11
+ <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
12
+ <triggers class="vector"><jenkins.triggers.ReverseBuildTrigger><spec/><upstreamProjects>UpstreamProject</upstreamProjects><threshold><name>FAILURE</name><ordinal>2</ordinal><color>RED</color><completeBuild>true</completeBuild></threshold></jenkins.triggers.ReverseBuildTrigger></triggers>
13
+ <concurrentBuild>false</concurrentBuild>
14
+ <builders/>
15
+ <publishers/>
16
+ <buildWrappers/>
17
+ </project>
@@ -0,0 +1,7 @@
1
+ ---
2
+ - job:
3
+ name: upstream
4
+ triggers:
5
+ - upstream:
6
+ projects: UpstreamProject
7
+ status: failed
@@ -35,8 +35,10 @@ describe 'Test YAML jobs conversion to XML' do
35
35
  'post_build_script',
36
36
  'properties_file',
37
37
  'downstream',
38
+ 'upstream',
38
39
  'rvm05',
39
40
  'prepare_environment',
41
+ 'remote_job',
40
42
  'throttle',
41
43
  'specific_priority',
42
44
  'periodic_build',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins_pipeline_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Moochnick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-05 00:00:00.000000000 Z
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -334,12 +334,16 @@ files:
334
334
  - spec/unit_tests/fixtures/files/project.yaml
335
335
  - spec/unit_tests/fixtures/files/properties_file.xml
336
336
  - spec/unit_tests/fixtures/files/properties_file.yaml
337
+ - spec/unit_tests/fixtures/files/remote_job.xml
338
+ - spec/unit_tests/fixtures/files/remote_job.yaml
337
339
  - spec/unit_tests/fixtures/files/rvm05.xml
338
340
  - spec/unit_tests/fixtures/files/rvm05.yaml
339
341
  - spec/unit_tests/fixtures/files/specific_priority.xml
340
342
  - spec/unit_tests/fixtures/files/specific_priority.yaml
341
343
  - spec/unit_tests/fixtures/files/throttle.xml
342
344
  - spec/unit_tests/fixtures/files/throttle.yaml
345
+ - spec/unit_tests/fixtures/files/upstream.xml
346
+ - spec/unit_tests/fixtures/files/upstream.yaml
343
347
  - spec/unit_tests/fixtures/templates/external_job.yaml
344
348
  - spec/unit_tests/fixtures/templates/project_with_jobs.yaml
345
349
  - spec/unit_tests/generator_spec.rb
@@ -402,12 +406,16 @@ test_files:
402
406
  - spec/unit_tests/fixtures/files/project.yaml
403
407
  - spec/unit_tests/fixtures/files/properties_file.xml
404
408
  - spec/unit_tests/fixtures/files/properties_file.yaml
409
+ - spec/unit_tests/fixtures/files/remote_job.xml
410
+ - spec/unit_tests/fixtures/files/remote_job.yaml
405
411
  - spec/unit_tests/fixtures/files/rvm05.xml
406
412
  - spec/unit_tests/fixtures/files/rvm05.yaml
407
413
  - spec/unit_tests/fixtures/files/specific_priority.xml
408
414
  - spec/unit_tests/fixtures/files/specific_priority.yaml
409
415
  - spec/unit_tests/fixtures/files/throttle.xml
410
416
  - spec/unit_tests/fixtures/files/throttle.yaml
417
+ - spec/unit_tests/fixtures/files/upstream.xml
418
+ - spec/unit_tests/fixtures/files/upstream.yaml
411
419
  - spec/unit_tests/fixtures/templates/external_job.yaml
412
420
  - spec/unit_tests/fixtures/templates/project_with_jobs.yaml
413
421
  - spec/unit_tests/generator_spec.rb