jenkins_pipeline_builder 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Rakefile +1 -1
- data/lib/jenkins_pipeline_builder.rb +33 -7
- data/lib/jenkins_pipeline_builder/builders.rb +8 -8
- data/lib/jenkins_pipeline_builder/cli/base.rb +11 -15
- data/lib/jenkins_pipeline_builder/cli/describe.rb +55 -0
- data/lib/jenkins_pipeline_builder/cli/helper.rb +2 -2
- data/lib/jenkins_pipeline_builder/cli/list.rb +47 -0
- data/lib/jenkins_pipeline_builder/extendable.rb +42 -0
- data/lib/jenkins_pipeline_builder/generator.rb +41 -89
- data/lib/jenkins_pipeline_builder/job_builder.rb +10 -10
- data/lib/jenkins_pipeline_builder/module_registry.rb +43 -3
- data/lib/jenkins_pipeline_builder/publishers.rb +19 -19
- data/lib/jenkins_pipeline_builder/pull_request.rb +29 -47
- data/lib/jenkins_pipeline_builder/triggers.rb +5 -5
- data/lib/jenkins_pipeline_builder/version.rb +1 -1
- data/lib/jenkins_pipeline_builder/wrappers.rb +10 -9
- data/spec/func_tests/view_spec.rb +2 -5
- data/spec/unit_tests/fixtures/pull_request/00.yaml +14 -0
- data/spec/unit_tests/fixtures/pull_request/10.yaml +7 -0
- data/spec/unit_tests/fixtures/pull_request/11.yaml +4 -0
- data/spec/unit_tests/fixtures/pull_request/project.yaml +11 -0
- data/spec/unit_tests/generator_spec.rb +12 -10
- data/spec/unit_tests/module_registry_spec.rb +7 -10
- data/spec/unit_tests/resolve_dependencies_spec.rb +12 -8
- data/spec/unit_tests/spec_helper.rb +1 -0
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1e9094c74dee6457c8b9feb1f72c386bec441a6
|
4
|
+
data.tar.gz: 3f9f57f5be8a20d1ed0ca2c0f988c99d827a05b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b8af333e06b4ccba511bb2f268081547b5208dcdffce6f1a3cdd14b6815e813e12f10b98071a95ac7ea4770522acf1f70e34e931ac3a051806fedb9a33a180c
|
7
|
+
data.tar.gz: 55148fc5a1bb693af47ffc1f47f805195cce2ca6222dbeb5cf3c55b61eb592cb3304b3d4cae882da02dba4fb929846cd3e981074b57208f0f12868c871bec6b1
|
data/.rubocop.yml
CHANGED
data/Rakefile
CHANGED
@@ -20,23 +20,49 @@
|
|
20
20
|
# THE SOFTWARE.
|
21
21
|
#
|
22
22
|
|
23
|
+
require 'active_support'
|
24
|
+
require 'active_support/core_ext'
|
25
|
+
|
23
26
|
require 'jenkins_pipeline_builder/version'
|
24
27
|
require 'jenkins_pipeline_builder/utils'
|
25
28
|
require 'jenkins_pipeline_builder/xml_helper'
|
29
|
+
require 'jenkins_pipeline_builder/extendable'
|
26
30
|
require 'jenkins_pipeline_builder/compiler'
|
27
|
-
require 'jenkins_pipeline_builder/job_builder'
|
28
31
|
require 'jenkins_pipeline_builder/module_registry'
|
29
|
-
require 'jenkins_pipeline_builder/builders'
|
30
|
-
require 'jenkins_pipeline_builder/wrappers'
|
31
|
-
require 'jenkins_pipeline_builder/triggers'
|
32
|
-
require 'jenkins_pipeline_builder/publishers'
|
33
32
|
require 'jenkins_pipeline_builder/pull_request'
|
34
33
|
require 'jenkins_pipeline_builder/view'
|
35
34
|
require 'jenkins_pipeline_builder/generator'
|
36
35
|
|
36
|
+
module JenkinsPipelineBuilder
|
37
|
+
class << self
|
38
|
+
attr_reader :client, :credentials
|
39
|
+
def generator
|
40
|
+
@_generator ||= Generator.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def credentials=(creds)
|
44
|
+
@credentials = creds
|
45
|
+
@client =
|
46
|
+
@_client = JenkinsApi::Client.new(credentials)
|
47
|
+
generator.logger = @_client.logger
|
48
|
+
@credentials
|
49
|
+
end
|
50
|
+
|
51
|
+
def registry
|
52
|
+
generator.module_registry
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
JenkinsPipelineBuilder.generator
|
57
|
+
require 'jenkins_pipeline_builder/builders'
|
58
|
+
require 'jenkins_pipeline_builder/job_builder'
|
59
|
+
require 'jenkins_pipeline_builder/wrappers'
|
60
|
+
require 'jenkins_pipeline_builder/publishers'
|
61
|
+
require 'jenkins_pipeline_builder/triggers'
|
62
|
+
|
37
63
|
require 'jenkins_pipeline_builder/cli/helper'
|
38
64
|
require 'jenkins_pipeline_builder/cli/view'
|
39
65
|
require 'jenkins_pipeline_builder/cli/pipeline'
|
66
|
+
require 'jenkins_pipeline_builder/cli/list'
|
67
|
+
require 'jenkins_pipeline_builder/cli/describe'
|
40
68
|
require 'jenkins_pipeline_builder/cli/base'
|
41
|
-
require 'active_support'
|
42
|
-
require 'active_support/core_ext'
|
@@ -21,8 +21,8 @@
|
|
21
21
|
#
|
22
22
|
|
23
23
|
module JenkinsPipelineBuilder
|
24
|
-
class Builders
|
25
|
-
|
24
|
+
class Builders < Extendable
|
25
|
+
register :multi_job do |params, xml|
|
26
26
|
params[:phases].each do |name, content|
|
27
27
|
xml.send('com.tikal.jenkins.plugins.multijob.MultiJobBuilder') do
|
28
28
|
xml.phaseName name
|
@@ -49,7 +49,7 @@ module JenkinsPipelineBuilder
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
register :maven3 do |params, xml|
|
53
53
|
xml.send('org.jfrog.hudson.maven3.Maven3Builder') do
|
54
54
|
xml.mavenName params[:mavenName] || 'tools-maven-3.0.3'
|
55
55
|
xml.rootPom params[:rootPom]
|
@@ -58,13 +58,13 @@ module JenkinsPipelineBuilder
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
register :shell_command do |param, xml|
|
62
62
|
xml.send('hudson.tasks.Shell') do
|
63
63
|
xml.command param
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
register :inject_vars_file do |params, xml|
|
68
68
|
xml.EnvInjectBuilder do
|
69
69
|
xml.info do
|
70
70
|
xml.propertiesFilePath params
|
@@ -72,7 +72,7 @@ module JenkinsPipelineBuilder
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
|
75
|
+
register :blocking_downstream do |params, xml|
|
76
76
|
colors = { 'SUCCESS' => { ordinal: 0, color: 'BLUE' }, 'FAILURE' => { ordinal: 2, color: 'RED' }, 'UNSTABLE' => { ordinal: 1, color: 'YELLOW' } }
|
77
77
|
xml.send('hudson.plugins.parameterizedtrigger.TriggerBuilder', 'plugin' => 'parameterized-trigger') do
|
78
78
|
xml.configs do
|
@@ -129,7 +129,7 @@ module JenkinsPipelineBuilder
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
|
132
|
+
register :remote_job do |params, xml|
|
133
133
|
parameters = params[:parameters][:content].split("\n") if params[:parameters] && params[:parameters][:content]
|
134
134
|
xml.send('org.jenkinsci.plugins.ParameterizedRemoteTrigger.RemoteBuildConfiguration', 'plugin' => 'Parameterized-Remote-Trigger') do
|
135
135
|
xml.remoteJenkinsName params[:server]
|
@@ -171,7 +171,7 @@ module JenkinsPipelineBuilder
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
-
|
174
|
+
register :copy_artifact do |params, xml|
|
175
175
|
xml.send('hudson.plugins.copyartifact.CopyArtifact', 'plugin' => 'copyartifact') do
|
176
176
|
xml.project params[:project]
|
177
177
|
xml.filter params[:artifacts]
|
@@ -41,21 +41,17 @@ module JenkinsPipelineBuilder
|
|
41
41
|
puts JenkinsPipelineBuilder::VERSION
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
'view',
|
56
|
-
'view [subcommand]',
|
57
|
-
'Provides functions to access view interface of Jenkins CI server'
|
58
|
-
)
|
44
|
+
desc 'pipeline [subcommand]', 'Provides functions to access pipeline functions of the Jenkins CI server'
|
45
|
+
subcommand 'pipeline', CLI::Pipeline
|
46
|
+
|
47
|
+
desc 'view [subcommand]', 'Provides functions to access view interface of Jenkins CI server'
|
48
|
+
subcommand 'view', CLI::View
|
49
|
+
|
50
|
+
desc 'list [type]', 'Lists all registered modules of a type'
|
51
|
+
subcommand 'list', List
|
52
|
+
|
53
|
+
desc 'describe [type]', 'Describe a module'
|
54
|
+
subcommand 'describe', Describe
|
59
55
|
end
|
60
56
|
end
|
61
57
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 Constant Contact
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
module JenkinsPipelineBuilder
|
24
|
+
module CLI
|
25
|
+
JenkinsPipelineBuilder.registry.entries.each do |entry, _path|
|
26
|
+
klass_name = entry.to_s.classify
|
27
|
+
klass = Class.new(Thor) do
|
28
|
+
|
29
|
+
modules = JenkinsPipelineBuilder.registry.registered_modules[entry]
|
30
|
+
modules.each do |mod, values|
|
31
|
+
desc mod, "Details for #{mod}"
|
32
|
+
define_method(mod) do
|
33
|
+
display_module(mod, values)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def display_module(mod, values)
|
40
|
+
puts "#{mod}: #{values[:description]}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
Module.const_set(klass_name, klass)
|
44
|
+
end
|
45
|
+
class Describe < Thor
|
46
|
+
JenkinsPipelineBuilder.registry.entries.each do |entry, _path|
|
47
|
+
klass_name = entry.to_s.classify
|
48
|
+
singular_model = entry.to_s.singularize
|
49
|
+
|
50
|
+
desc "#{singular_model} [module]", 'Shows details for the named module'
|
51
|
+
subcommand singular_model, Module.const_get(klass_name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -56,8 +56,8 @@ module JenkinsPipelineBuilder
|
|
56
56
|
exit 1
|
57
57
|
end
|
58
58
|
|
59
|
-
|
60
|
-
generator = JenkinsPipelineBuilder
|
59
|
+
JenkinsPipelineBuilder.credentials = creds
|
60
|
+
generator = JenkinsPipelineBuilder.generator
|
61
61
|
generator.debug = options[:debug]
|
62
62
|
generator
|
63
63
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 Constant Contact
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
module JenkinsPipelineBuilder
|
24
|
+
module CLI
|
25
|
+
class List < Thor
|
26
|
+
JenkinsPipelineBuilder.registry.entries.each do |entry, _path|
|
27
|
+
desc entry, "List all #{entry}"
|
28
|
+
define_method(entry) do
|
29
|
+
modules = JenkinsPipelineBuilder.registry.registered_modules[entry]
|
30
|
+
modules.each { |mod, values| display_module(mod, values) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'job_attributes', 'List all job attributes'
|
35
|
+
def job_attributes
|
36
|
+
modules = JenkinsPipelineBuilder.registry.registered_modules[:job_attributes]
|
37
|
+
modules.each { |mod, values| display_module(mod, values) }
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def display_module(mod, values)
|
43
|
+
puts "#{mod}: Jenkins Name: #{values[:jenkins_name]}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014 Constant Contact
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
module JenkinsPipelineBuilder
|
24
|
+
class Extendable
|
25
|
+
def self.register(name, jenkins_name: 'No jenkins display name provided', description: 'No description provided', &block)
|
26
|
+
registry = JenkinsPipelineBuilder.registry
|
27
|
+
registry.send(class_to_registry_method(to_s), name, jenkins_name, description, &block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.class_to_registry_method(name)
|
31
|
+
h = {
|
32
|
+
'JenkinsPipelineBuilder::JobBuilder' => :register_job_attribute,
|
33
|
+
'JenkinsPipelineBuilder::Builders' => :register_builder,
|
34
|
+
'JenkinsPipelineBuilder::Publishers' => :register_publisher,
|
35
|
+
'JenkinsPipelineBuilder::Wrappers' => :register_wrapper,
|
36
|
+
'JenkinsPipelineBuilder::Triggers' => :register_trigger
|
37
|
+
}
|
38
|
+
fail "Unknown class #{name} when adding an extension. Known classes are #{h.keys.join ', '}" unless h.key?(name)
|
39
|
+
h[name]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -35,80 +35,12 @@ module JenkinsPipelineBuilder
|
|
35
35
|
#
|
36
36
|
# @raise [ArgumentError] when required options are not provided.
|
37
37
|
#
|
38
|
-
def initialize
|
39
|
-
@client = client
|
40
|
-
@logger = @client.logger
|
41
|
-
# @logger.level = (@debug) ? Logger::DEBUG : Logger::INFO;
|
38
|
+
def initialize
|
42
39
|
@job_templates = {}
|
43
40
|
@job_collection = {}
|
44
41
|
@extensions = {}
|
45
42
|
@remote_depends = {}
|
46
|
-
|
47
|
-
@module_registry = ModuleRegistry.new(
|
48
|
-
job: {
|
49
|
-
description: JobBuilder.method(:change_description),
|
50
|
-
scm_params: JobBuilder.method(:apply_scm_params),
|
51
|
-
hipchat: JobBuilder.method(:hipchat_notifier),
|
52
|
-
parameters: JobBuilder.method(:build_parameters),
|
53
|
-
priority: JobBuilder.method(:use_specific_priority),
|
54
|
-
discard_old: JobBuilder.method(:discard_old_param),
|
55
|
-
throttle: JobBuilder.method(:throttle_job),
|
56
|
-
prepare_environment: JobBuilder.method(:prepare_environment),
|
57
|
-
concurrent_build: JobBuilder.method(:concurrent_build),
|
58
|
-
builders: {
|
59
|
-
registry: {
|
60
|
-
multi_job: Builders.method(:build_multijob),
|
61
|
-
inject_vars_file: Builders.method(:build_environment_vars_injector),
|
62
|
-
shell_command: Builders.method(:build_shell_command),
|
63
|
-
maven3: Builders.method(:build_maven3),
|
64
|
-
blocking_downstream: Builders.method(:blocking_downstream),
|
65
|
-
remote_job: Builders.method(:start_remote_job),
|
66
|
-
copy_artifact: Builders.method(:build_copy_artifact)
|
67
|
-
},
|
68
|
-
method:
|
69
|
-
->(registry, params, n_xml) { @module_registry.run_registry_on_path('//builders', registry, params, n_xml) }
|
70
|
-
},
|
71
|
-
publishers: {
|
72
|
-
registry: {
|
73
|
-
git: Publishers.method(:push_to_git),
|
74
|
-
hipchat: Publishers.method(:push_to_hipchat),
|
75
|
-
description_setter: Publishers.method(:description_setter),
|
76
|
-
downstream: Publishers.method(:push_to_projects),
|
77
|
-
junit_result: Publishers.method(:publish_junit),
|
78
|
-
coverage_result: Publishers.method(:publish_rcov),
|
79
|
-
post_build_script: Publishers.method(:post_build_script),
|
80
|
-
groovy_postbuild: Publishers.method(:groovy_postbuild),
|
81
|
-
archive_artifact: Publishers.method(:archive_artifact)
|
82
|
-
},
|
83
|
-
method:
|
84
|
-
->(registry, params, n_xml) { @module_registry.run_registry_on_path('//publishers', registry, params, n_xml) }
|
85
|
-
},
|
86
|
-
wrappers: {
|
87
|
-
registry: {
|
88
|
-
timestamp: Wrappers.method(:console_timestamp),
|
89
|
-
ansicolor: Wrappers.method(:ansicolor),
|
90
|
-
artifactory: Wrappers.method(:publish_to_artifactory),
|
91
|
-
rvm: Wrappers.method(:run_with_rvm),
|
92
|
-
rvm05: Wrappers.method(:run_with_rvm05),
|
93
|
-
inject_env_var: Wrappers.method(:inject_env_vars),
|
94
|
-
inject_passwords: Wrappers.method(:inject_passwords),
|
95
|
-
maven3artifactory: Wrappers.method(:artifactory_maven3_configurator)
|
96
|
-
},
|
97
|
-
method:
|
98
|
-
->(registry, params, n_xml) { @module_registry.run_registry_on_path('//buildWrappers', registry, params, n_xml) }
|
99
|
-
},
|
100
|
-
triggers: {
|
101
|
-
registry: {
|
102
|
-
git_push: Triggers.method(:enable_git_push),
|
103
|
-
scm_polling: Triggers.method(:enable_scm_polling),
|
104
|
-
periodic_build: Triggers.method(:enable_periodic_build),
|
105
|
-
upstream: Triggers.method(:enable_upstream_check)
|
106
|
-
},
|
107
|
-
method:
|
108
|
-
->(registry, params, n_xml) { @module_registry.run_registry_on_path('//triggers', registry, params, n_xml) }
|
109
|
-
}
|
110
|
-
}
|
111
|
-
)
|
43
|
+
@module_registry = ModuleRegistry.new
|
112
44
|
end
|
113
45
|
|
114
46
|
def load_extensions(path)
|
@@ -148,10 +80,12 @@ module JenkinsPipelineBuilder
|
|
148
80
|
@logger.level = (value) ? Logger::DEBUG : Logger::INFO
|
149
81
|
end
|
150
82
|
|
83
|
+
def client
|
84
|
+
JenkinsPipelineBuilder.client
|
85
|
+
end
|
86
|
+
|
151
87
|
attr_reader :debug
|
152
|
-
attr_accessor :
|
153
|
-
attr_accessor :no_files
|
154
|
-
attr_accessor :job_collection
|
88
|
+
attr_accessor :no_files, :job_collection, :logger, :module_registry
|
155
89
|
|
156
90
|
# Creates an instance to the View class by passing a reference to self
|
157
91
|
#
|
@@ -191,9 +125,9 @@ module JenkinsPipelineBuilder
|
|
191
125
|
value = section[key]
|
192
126
|
if key == :dependencies
|
193
127
|
@logger.info 'Resolving Dependencies for remote project'
|
194
|
-
|
128
|
+
load_remote_yaml(value)
|
129
|
+
next
|
195
130
|
end
|
196
|
-
|
197
131
|
name = value[:name]
|
198
132
|
if @job_collection.key?(name)
|
199
133
|
if remote
|
@@ -275,11 +209,11 @@ module JenkinsPipelineBuilder
|
|
275
209
|
return load_collection_from_path(path)
|
276
210
|
end
|
277
211
|
|
278
|
-
load_templates(source[:templates])
|
212
|
+
load_templates(path, source[:templates])
|
279
213
|
end
|
280
214
|
end
|
281
215
|
|
282
|
-
def load_templates(templates)
|
216
|
+
def load_templates(path, templates)
|
283
217
|
templates.each do |template|
|
284
218
|
version = template[:version] || 'newest'
|
285
219
|
@logger.info "Loading #{template[:name]} at version #{version}"
|
@@ -355,7 +289,6 @@ module JenkinsPipelineBuilder
|
|
355
289
|
def resolve_project(project)
|
356
290
|
defaults = get_item('global')
|
357
291
|
settings = defaults.nil? ? {} : defaults[:value] || {}
|
358
|
-
|
359
292
|
project[:settings] = Compiler.get_settings_bag(project, settings) unless project[:settings]
|
360
293
|
project_body = project[:value]
|
361
294
|
|
@@ -363,7 +296,7 @@ module JenkinsPipelineBuilder
|
|
363
296
|
@logger.info project
|
364
297
|
process_job_changes(jobs)
|
365
298
|
errors = process_jobs(jobs, project)
|
366
|
-
errors =
|
299
|
+
errors = process_views(project_body[:views], project, errors) if project_body[:views]
|
367
300
|
|
368
301
|
errors.each do |k, v|
|
369
302
|
puts "Encountered errors processing: #{k}:"
|
@@ -404,7 +337,7 @@ module JenkinsPipelineBuilder
|
|
404
337
|
|
405
338
|
def publish_project(project_name, errors = {})
|
406
339
|
projects.each do |project|
|
407
|
-
next
|
340
|
+
next unless project_name.nil? || project[:name] == project_name
|
408
341
|
success, payload = resolve_project(project)
|
409
342
|
if success
|
410
343
|
puts 'successfully resolved project'
|
@@ -445,6 +378,7 @@ module JenkinsPipelineBuilder
|
|
445
378
|
def bootstrap(path, project_name)
|
446
379
|
@logger.info "Bootstrapping pipeline from path #{path}"
|
447
380
|
load_collection_from_path(path)
|
381
|
+
@logger.info @job_collection
|
448
382
|
cleanup_temp_remote
|
449
383
|
load_extensions(path)
|
450
384
|
errors = {}
|
@@ -466,6 +400,7 @@ module JenkinsPipelineBuilder
|
|
466
400
|
cleanup_temp_remote
|
467
401
|
load_extensions(path)
|
468
402
|
jobs = {}
|
403
|
+
@logger.info "Project: #{projects}"
|
469
404
|
projects.each do |project|
|
470
405
|
if project[:name] == project_name || project_name.nil?
|
471
406
|
project_body = project[:value]
|
@@ -473,6 +408,7 @@ module JenkinsPipelineBuilder
|
|
473
408
|
@logger.info "Using Project #{project}"
|
474
409
|
pull_job = nil
|
475
410
|
project_jobs.each do |job|
|
411
|
+
job = job.keys.first if job.is_a? Hash
|
476
412
|
job = @job_collection[job.to_s]
|
477
413
|
pull_job = job if job[:value][:job_type] == 'pull_request_generator'
|
478
414
|
end
|
@@ -482,11 +418,27 @@ module JenkinsPipelineBuilder
|
|
482
418
|
if job.is_a? String
|
483
419
|
jobs[job.to_s] = @job_collection[job.to_s]
|
484
420
|
else
|
485
|
-
jobs[job.keys
|
421
|
+
jobs[job.keys.first.to_s] = @job_collection[job.keys.first.to_s]
|
422
|
+
end
|
423
|
+
end
|
424
|
+
pull = JenkinsPipelineBuilder::PullRequestGenerator.new(project, jobs, pull_job)
|
425
|
+
# Build the jobs
|
426
|
+
@job_collection.merge! pull.jobs
|
427
|
+
pull.create.each do |project|
|
428
|
+
success, compiled_project = resolve_project(project)
|
429
|
+
compiled_project[:value][:jobs].each do |i|
|
430
|
+
job = i[:result]
|
431
|
+
success, payload = compile_job_to_xml(job)
|
432
|
+
create_or_update(job, payload) if success
|
433
|
+
end
|
434
|
+
end
|
435
|
+
# Purge old jobs
|
436
|
+
pull.purge.each do |job|
|
437
|
+
jobs = @client.job.list "#{job}.*"
|
438
|
+
jobs.each do |job|
|
439
|
+
@client.job.delete job
|
486
440
|
end
|
487
441
|
end
|
488
|
-
pull = JenkinsPipelineBuilder::PullRequestGenerator.new(self)
|
489
|
-
pull.run(project, jobs, pull_job)
|
490
442
|
end
|
491
443
|
end
|
492
444
|
end
|
@@ -494,7 +446,7 @@ module JenkinsPipelineBuilder
|
|
494
446
|
def dump(job_name)
|
495
447
|
@logger.info "Debug #{@debug}"
|
496
448
|
@logger.info "Dumping #{job_name} into #{job_name}.xml"
|
497
|
-
xml =
|
449
|
+
xml = client.job.get_config(job_name)
|
498
450
|
File.open(job_name + '.xml', 'w') { |f| f.write xml }
|
499
451
|
end
|
500
452
|
|
@@ -507,10 +459,10 @@ module JenkinsPipelineBuilder
|
|
507
459
|
return
|
508
460
|
end
|
509
461
|
|
510
|
-
if
|
511
|
-
|
462
|
+
if client.job.exists?(job_name)
|
463
|
+
client.job.update(job_name, xml)
|
512
464
|
else
|
513
|
-
|
465
|
+
client.job.create(job_name, xml)
|
514
466
|
end
|
515
467
|
end
|
516
468
|
|
@@ -556,7 +508,7 @@ module JenkinsPipelineBuilder
|
|
556
508
|
puts "Template merged: #{template}"
|
557
509
|
end
|
558
510
|
|
559
|
-
xml =
|
511
|
+
xml = client.job.build_freestyle_config(params)
|
560
512
|
n_xml = Nokogiri::XML(xml)
|
561
513
|
|
562
514
|
@module_registry.traverse_registry_path('job', params, n_xml)
|
@@ -586,7 +538,7 @@ module JenkinsPipelineBuilder
|
|
586
538
|
def generate_job_dsl_body(params)
|
587
539
|
@logger.info 'Generating pipeline'
|
588
540
|
|
589
|
-
xml =
|
541
|
+
xml = client.job.build_freestyle_config(params)
|
590
542
|
|
591
543
|
n_xml = Nokogiri::XML(xml)
|
592
544
|
if n_xml.xpath('//javaposse.jobdsl.plugin.ExecuteDslScripts').empty?
|
@@ -21,13 +21,13 @@
|
|
21
21
|
#
|
22
22
|
|
23
23
|
module JenkinsPipelineBuilder
|
24
|
-
class JobBuilder
|
25
|
-
|
24
|
+
class JobBuilder < Extendable
|
25
|
+
register :description do |description, n_xml|
|
26
26
|
desc = n_xml.xpath('//description').first
|
27
27
|
desc.content = "#{description}"
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
register :scm_params do |params, n_xml|
|
31
31
|
XmlHelper.update_node_text(n_xml, '//scm/localBranch', params[:local_branch]) if params[:local_branch]
|
32
32
|
XmlHelper.update_node_text(n_xml, '//scm/recursiveSubmodules', params[:recursive_update]) if params[:recursive_update]
|
33
33
|
XmlHelper.update_node_text(n_xml, '//scm/wipeOutWorkspace', params[:wipe_workspace]) if params[:wipe_workspace]
|
@@ -39,7 +39,7 @@ module JenkinsPipelineBuilder
|
|
39
39
|
XmlHelper.update_node_text(n_xml, '//scm/includedRegions', params[:included_regions]) if params[:included_regions]
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
register :hipchat do |params, n_xml|
|
43
43
|
fail 'No HipChat room specified' unless params[:room]
|
44
44
|
|
45
45
|
properties = n_xml.xpath('//properties').first
|
@@ -51,7 +51,7 @@ module JenkinsPipelineBuilder
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
register :priority do |params, n_xml|
|
55
55
|
n_builders = n_xml.xpath('//properties').first
|
56
56
|
Nokogiri::XML::Builder.with(n_builders) do |xml|
|
57
57
|
xml.send('jenkins.advancedqueue.AdvancedQueueSorterJobProperty', 'plugin' => 'PrioritySorter') do
|
@@ -61,7 +61,7 @@ module JenkinsPipelineBuilder
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
|
64
|
+
register :parameters do |params, n_xml|
|
65
65
|
n_builders = n_xml.xpath('//properties').first
|
66
66
|
Nokogiri::XML::Builder.with(n_builders) do |xml|
|
67
67
|
xml.send('hudson.model.ParametersDefinitionProperty') do
|
@@ -105,7 +105,7 @@ module JenkinsPipelineBuilder
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
|
108
|
+
register :discard_old do |params, n_xml|
|
109
109
|
properties = n_xml.child
|
110
110
|
Nokogiri::XML::Builder.with(properties) do |xml|
|
111
111
|
xml.send('logRotator', 'class' => 'hudson.tasks.LogRotator') do
|
@@ -117,7 +117,7 @@ module JenkinsPipelineBuilder
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
|
120
|
+
register :throttle do |params, n_xml|
|
121
121
|
properties = n_xml.xpath('//properties').first
|
122
122
|
cat_set = params[:option] == 'category'
|
123
123
|
Nokogiri::XML::Builder.with(properties) do |xml|
|
@@ -133,7 +133,7 @@ module JenkinsPipelineBuilder
|
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
|
136
|
+
register :prepare_environment do |params, n_xml|
|
137
137
|
properties = n_xml.xpath('//properties').first
|
138
138
|
Nokogiri::XML::Builder.with(properties) do |xml|
|
139
139
|
xml.send('EnvInjectJobProperty') do
|
@@ -148,7 +148,7 @@ module JenkinsPipelineBuilder
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
-
|
151
|
+
register :concurrent_build do |params, n_xml|
|
152
152
|
concurrentBuild = n_xml.xpath('//concurrentBuild').first
|
153
153
|
concurrentBuild.content = (params == true) ? 'true' : 'false'
|
154
154
|
end
|
@@ -22,10 +22,50 @@
|
|
22
22
|
|
23
23
|
module JenkinsPipelineBuilder
|
24
24
|
class ModuleRegistry
|
25
|
-
attr_accessor :registry
|
25
|
+
attr_accessor :registry, :registered_modules
|
26
|
+
ENTRIES = {
|
27
|
+
builders: '//builders',
|
28
|
+
publishers: '//publishers',
|
29
|
+
wrappers: '//buildWrappers',
|
30
|
+
triggers: '//triggers'
|
31
|
+
}
|
26
32
|
|
27
|
-
|
28
|
-
|
33
|
+
# creates register_triggers and so on
|
34
|
+
# we declare job attribues below since it doesn't follow the pattern
|
35
|
+
ENTRIES.keys.each do |key|
|
36
|
+
# TODO: Too lazy to figure out a better way to do this
|
37
|
+
singular_key = key.to_s.singularize.to_sym
|
38
|
+
define_method "register_#{singular_key}" do |name, jenkins_name, description, &block|
|
39
|
+
@registered_modules[key][name] = {
|
40
|
+
jenkins_name: jenkins_name,
|
41
|
+
description: description
|
42
|
+
}
|
43
|
+
@registry[:job][key][:registry][name] = block
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize
|
48
|
+
@registry = { job: {} }
|
49
|
+
@registered_modules = { job_attributes: {} }
|
50
|
+
|
51
|
+
entries.each do |key, value|
|
52
|
+
@registered_modules[key] = {}
|
53
|
+
@registry[:job][key] = {}
|
54
|
+
@registry[:job][key][:registry] = {}
|
55
|
+
@registry[:job][key][:method] = ->(registry, params, n_xml) { run_registry_on_path(value, registry, params, n_xml) }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def entries
|
60
|
+
ENTRIES
|
61
|
+
end
|
62
|
+
|
63
|
+
def register_job_attribute(name, jenkins_name, description, &block)
|
64
|
+
@registered_modules[:job_attributes][name] = {
|
65
|
+
jenkins_name: jenkins_name,
|
66
|
+
description: description
|
67
|
+
}
|
68
|
+
@registry[:job][name] = block
|
29
69
|
end
|
30
70
|
|
31
71
|
def get(path)
|
@@ -21,8 +21,8 @@
|
|
21
21
|
#
|
22
22
|
|
23
23
|
module JenkinsPipelineBuilder
|
24
|
-
class Publishers
|
25
|
-
|
24
|
+
class Publishers < Extendable
|
25
|
+
register :description_setter do |params, xml|
|
26
26
|
xml.send('hudson.plugins.descriptionsetter.DescriptionSetterPublisher') do
|
27
27
|
xml.regexp params[:regexp]
|
28
28
|
xml.regexpForFailed params[:regexp]
|
@@ -32,7 +32,7 @@ module JenkinsPipelineBuilder
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
register :downstream do |params, xml|
|
36
36
|
xml.send('hudson.plugins.parameterizedtrigger.BuildTrigger') do
|
37
37
|
xml.configs do
|
38
38
|
xml.send('hudson.plugins.parameterizedtrigger.BuildTriggerConfig') do
|
@@ -60,7 +60,7 @@ module JenkinsPipelineBuilder
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
register :hipchat do |params, xml|
|
64
64
|
params = {} if params == true
|
65
65
|
xml.send('jenkins.plugins.hipchat.HipChatNotifier') do
|
66
66
|
xml.jenkinsUrl params[:jenkinsUrl] || ''
|
@@ -69,7 +69,7 @@ module JenkinsPipelineBuilder
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
|
72
|
+
register :git do |params, xml|
|
73
73
|
xml.send('hudson.plugins.git.GitPublisher') do
|
74
74
|
xml.configVersion params[:configVersion] || 2
|
75
75
|
xml.pushMerge params[:'push-merge'] || false
|
@@ -83,7 +83,7 @@ module JenkinsPipelineBuilder
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
|
86
|
+
register :junit_result do |params, xml|
|
87
87
|
xml.send('hudson.tasks.junit.JUnitResultArchiver') do
|
88
88
|
xml.testResults params[:test_results] || ''
|
89
89
|
xml.keepLongStdio false
|
@@ -91,16 +91,7 @@ module JenkinsPipelineBuilder
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
|
95
|
-
xml.send('hudson.plugins.rubyMetrics.rcov.model.MetricTarget') do
|
96
|
-
xml.metric name
|
97
|
-
xml.healthy params[:healthy]
|
98
|
-
xml.unhealthy params[:unhealthy]
|
99
|
-
xml.unstable params[:unstable]
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.publish_rcov(params, xml)
|
94
|
+
register :coverage_result do |params, xml|
|
104
95
|
xml.send('hudson.plugins.rubyMetrics.rcov.RcovPublisher') do
|
105
96
|
xml.reportDir params[:report_dir]
|
106
97
|
xml.targets do
|
@@ -110,7 +101,7 @@ module JenkinsPipelineBuilder
|
|
110
101
|
end
|
111
102
|
end
|
112
103
|
|
113
|
-
|
104
|
+
register :post_build_script do |params, xml|
|
114
105
|
xml.send('org.jenkinsci.plugins.postbuildscript.PostBuildScript') do
|
115
106
|
xml.buildSteps do
|
116
107
|
if params[:shell_command]
|
@@ -125,7 +116,7 @@ module JenkinsPipelineBuilder
|
|
125
116
|
end
|
126
117
|
end
|
127
118
|
|
128
|
-
|
119
|
+
register :groovy_postbuild do |params, xml|
|
129
120
|
xml.send('org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder', 'plugin' => 'groovy-postbuild') do
|
130
121
|
xml.groovyScript params[:groovy_script]
|
131
122
|
xml.behavior params[:behavior] || '0'
|
@@ -140,7 +131,7 @@ module JenkinsPipelineBuilder
|
|
140
131
|
end
|
141
132
|
end
|
142
133
|
|
143
|
-
|
134
|
+
register :archive_artifact do |params, xml|
|
144
135
|
xml.send('hudson.tasks.ArtifactArchiver') do
|
145
136
|
xml.artifacts params[:artifacts]
|
146
137
|
xml.excludes params[:excludes] if params[:excludes]
|
@@ -148,5 +139,14 @@ module JenkinsPipelineBuilder
|
|
148
139
|
xml.allowEmptyArchive params[:allow_empty] || false
|
149
140
|
end
|
150
141
|
end
|
142
|
+
|
143
|
+
def self.coverage_metric(name, params, xml)
|
144
|
+
xml.send('hudson.plugins.rubyMetrics.rcov.model.MetricTarget') do
|
145
|
+
xml.metric name
|
146
|
+
xml.healthy params[:healthy]
|
147
|
+
xml.unhealthy params[:unhealthy]
|
148
|
+
xml.unstable params[:unstable]
|
149
|
+
end
|
150
|
+
end
|
151
151
|
end
|
152
152
|
end
|
@@ -22,18 +22,31 @@
|
|
22
22
|
|
23
23
|
module JenkinsPipelineBuilder
|
24
24
|
class PullRequestGenerator
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@
|
33
|
-
|
34
|
-
|
25
|
+
attr_reader :purge
|
26
|
+
attr_reader :create
|
27
|
+
attr_reader :jobs
|
28
|
+
|
29
|
+
def initialize(project, job_collection, generator_job)
|
30
|
+
@purge = []
|
31
|
+
@create = []
|
32
|
+
@jobs = {}
|
33
|
+
|
34
|
+
pull_requests = check_for_pull generator_job[:value]
|
35
|
+
purge_old(pull_requests, project)
|
36
|
+
pull_requests.each do |number|
|
37
|
+
# Manipulate the YAML
|
38
|
+
req = JenkinsPipelineBuilder::PullRequest.new(project, number, job_collection, generator_job)
|
39
|
+
@jobs.merge! req.jobs
|
40
|
+
project_t = req.project
|
41
|
+
|
42
|
+
# Overwrite the jobs from the generator to the project
|
43
|
+
project_t[:value][:jobs] = generator_job[:value][:jobs]
|
44
|
+
@create << project_t
|
45
|
+
end
|
35
46
|
end
|
36
47
|
|
48
|
+
private
|
49
|
+
|
37
50
|
# Check for Github Pull Requests
|
38
51
|
#
|
39
52
|
# args[:git_url] URL to the github main page ex. https://www.github.com/
|
@@ -54,49 +67,16 @@ module JenkinsPipelineBuilder
|
|
54
67
|
# Purge old builds
|
55
68
|
def purge_old(pull_requests, project)
|
56
69
|
reqs = pull_requests.clone.map { |req| "#{project[:name]}-PR#{req}" }
|
57
|
-
@logger.info "Current pull requests: #{reqs}"
|
58
70
|
# Read File
|
59
71
|
old_requests = File.new('pull_requests.csv', 'a+').read.split(',')
|
60
72
|
|
61
73
|
# Pop off current pull requests
|
62
74
|
old_requests.delete_if { |req| reqs.include?("#{req}") }
|
75
|
+
@purge = old_requests
|
63
76
|
|
64
|
-
# Delete the old requests from jenkins
|
65
|
-
@logger.info "Purging old requests: #{old_requests}"
|
66
|
-
old_requests.each do |req|
|
67
|
-
jobs = @client.job.list "#{req}.*"
|
68
|
-
jobs.each do |job|
|
69
|
-
@client.job.delete job
|
70
|
-
end
|
71
|
-
end
|
72
77
|
# Write File
|
73
78
|
File.open('pull_requests.csv', 'w+') { |file| file.write reqs.join(',') }
|
74
79
|
end
|
75
|
-
|
76
|
-
def run(project, job_collection, generator_job)
|
77
|
-
@logger.info 'Begin running Pull Request Generator'
|
78
|
-
pull_requests = check_for_pull generator_job[:value]
|
79
|
-
purge_old(pull_requests, project)
|
80
|
-
main_collection = job_collection
|
81
|
-
@logger.info pull_requests
|
82
|
-
pull_requests.each do |number|
|
83
|
-
# Manipulate the YAML
|
84
|
-
req = JenkinsPipelineBuilder::PullRequest.new(project, number, main_collection, generator_job)
|
85
|
-
@generator.job_collection.merge req.jobs
|
86
|
-
project = req.project
|
87
|
-
|
88
|
-
# Overwrite the jobs from the generator to the project
|
89
|
-
project[:value][:jobs] = generator_job[:value][:jobs]
|
90
|
-
|
91
|
-
# Build the jobs
|
92
|
-
success, compiled_project = @generator.resolve_project(project)
|
93
|
-
compiled_project[:value][:jobs].each do |i|
|
94
|
-
job = i[:result]
|
95
|
-
success, payload = @generator.compile_job_to_xml(job)
|
96
|
-
@generator.create_or_update(job, payload) if success
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
80
|
end
|
101
81
|
|
102
82
|
class PullRequest
|
@@ -107,11 +87,13 @@ module JenkinsPipelineBuilder
|
|
107
87
|
|
108
88
|
# Initialize
|
109
89
|
def initialize(project, number, jobs, generator)
|
110
|
-
|
90
|
+
# Set instance vars
|
91
|
+
@project = Marshal.load(Marshal.dump(project))
|
111
92
|
@number = number
|
112
|
-
@jobs = jobs
|
113
|
-
@generator = generator
|
93
|
+
@jobs = Marshal.load(Marshal.dump(jobs))
|
94
|
+
@generator = Marshal.load(Marshal.dump(generator))
|
114
95
|
|
96
|
+
# Run
|
115
97
|
run!
|
116
98
|
end
|
117
99
|
|
@@ -21,27 +21,27 @@
|
|
21
21
|
#
|
22
22
|
|
23
23
|
module JenkinsPipelineBuilder
|
24
|
-
class Triggers
|
25
|
-
|
24
|
+
class Triggers < Extendable
|
25
|
+
register :git_push do |_, xml|
|
26
26
|
xml.send('com.cloudbees.jenkins.GitHubPushTrigger') do
|
27
27
|
xml.spec
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
register :scm_polling do |scm_polling, xml|
|
32
32
|
xml.send('hudson.triggers.SCMTrigger') do
|
33
33
|
xml.spec scm_polling
|
34
34
|
xml.ignorePostCommitHooks false
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
register :periodic_build do |periodic_build, xml|
|
39
39
|
xml.send('hudson.triggers.TimerTrigger') do
|
40
40
|
xml.spec periodic_build
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
register :upstream do |params, xml|
|
45
45
|
case params[:status]
|
46
46
|
when 'unstable'
|
47
47
|
name = 'UNSTABLE'
|
@@ -21,18 +21,18 @@
|
|
21
21
|
#
|
22
22
|
|
23
23
|
module JenkinsPipelineBuilder
|
24
|
-
class Wrappers
|
25
|
-
|
24
|
+
class Wrappers < Extendable
|
25
|
+
register :ansicolor, jenkins_name: 'color ansi', description: 'this is a description' do |_, xml|
|
26
26
|
xml.send('hudson.plugins.ansicolor.AnsiColorBuildWrapper') do
|
27
27
|
xml.colorMapName 'xterm'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
register :timestamp do |_, xml|
|
32
32
|
xml.send('hudson.plugins.timestamper.TimestamperBuildWrapper', 'plugin' => 'timestamper')
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
register :rvm05 do |wrapper, xml|
|
36
36
|
xml.send('ruby-proxy-object') do
|
37
37
|
xml.send('ruby-object', 'ruby-class' => 'Jenkins::Tasks::BuildWrapperProxy', 'pluginid' => 'rvm') do
|
38
38
|
xml.object('ruby-class' => 'RvmWrapper', 'pluginid' => 'rvm') do
|
@@ -42,7 +42,8 @@ module JenkinsPipelineBuilder
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
|
+
register :rvm do |wrapper, xml|
|
46
47
|
xml.send('ruby-proxy-object') do
|
47
48
|
xml.send('ruby-object', 'ruby-class' => 'Jenkins::Plugin::Proxies::BuildWrapper', 'pluginid' => 'rvm') do
|
48
49
|
xml.object('ruby-class' => 'RvmWrapper', 'pluginid' => 'rvm') do
|
@@ -53,7 +54,7 @@ module JenkinsPipelineBuilder
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
|
-
|
57
|
+
register :inject_passwords do |passwords, xml|
|
57
58
|
xml.EnvInjectPasswordWrapper do
|
58
59
|
xml.injectGlobalPasswords false
|
59
60
|
xml.passwordEntries do
|
@@ -67,7 +68,7 @@ module JenkinsPipelineBuilder
|
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
70
|
-
|
71
|
+
register :inject_env_var do |params, xml|
|
71
72
|
xml.EnvInjectBuildWrapper do
|
72
73
|
xml.info do
|
73
74
|
xml.propertiesFilePath params[:file] if params[:file]
|
@@ -77,7 +78,7 @@ module JenkinsPipelineBuilder
|
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
80
|
-
|
81
|
+
register :artifactory do |wrapper, xml|
|
81
82
|
xml.send('org.jfrog.hudson.generic.ArtifactoryGenericConfigurator') do
|
82
83
|
xml.details do
|
83
84
|
xml.artifactoryUrl wrapper[:url]
|
@@ -99,7 +100,7 @@ module JenkinsPipelineBuilder
|
|
99
100
|
end
|
100
101
|
end
|
101
102
|
|
102
|
-
|
103
|
+
register :maven3artifactory do |wrapper, xml|
|
103
104
|
xml.send('org.jfrog.hudson.maven3.ArtifactoryMaven3Configurator') do # plugin='artifactory@2.2.1'
|
104
105
|
xml.details do
|
105
106
|
xml.artifactoryUrl wrapper[:url]
|
@@ -6,11 +6,8 @@ describe JenkinsPipelineBuilder::View do
|
|
6
6
|
@creds_file = '~/.jenkins_api_client/login.yml'
|
7
7
|
@valid_post_responses = [200, 201, 302]
|
8
8
|
begin
|
9
|
-
|
10
|
-
|
11
|
-
)
|
12
|
-
@client.logger.level = Logger::DEBUG
|
13
|
-
@generator = JenkinsPipelineBuilder::Generator.new(@client)
|
9
|
+
JenksinPipelineBuilder.credentials = YAML.load_file(File.expand_path(@creds_file, __FILE__))
|
10
|
+
@generator = JenkinsPipelineBuilder.generator
|
14
11
|
@generator.no_files = true
|
15
12
|
rescue StandardError => e
|
16
13
|
puts 'WARNING: Credentials are not set properly.'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
- job:
|
3
|
+
name: '{{name}}-00'
|
4
|
+
job_type: pull_request_generator
|
5
|
+
git_url: 'https://www.github.com/'
|
6
|
+
git_repo: 'constantcontact'
|
7
|
+
git_org: 'jenkins_pipeline_builder'
|
8
|
+
jobs:
|
9
|
+
- '{{name}}-10'
|
10
|
+
- '{{name}}-11'
|
11
|
+
builders:
|
12
|
+
- shell_command: |
|
13
|
+
generate -v || gem install jenkins_pipeline_builder
|
14
|
+
generate pipeline -c config/{{login_config}} pull_request pipeline/ {{name}}
|
@@ -3,18 +3,22 @@ require 'unit_tests/spec_helper'
|
|
3
3
|
describe 'Test YAML jobs conversion to XML' do
|
4
4
|
context 'Loading YAML files' do
|
5
5
|
before do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@generator = JenkinsPipelineBuilder
|
6
|
+
JenkinsPipelineBuilder.credentials = {
|
7
|
+
server_ip: '127.0.0.1',
|
8
|
+
server_port: 8080,
|
9
|
+
username: 'username',
|
10
|
+
password: 'password',
|
11
|
+
log_location: '/dev/null'
|
12
|
+
}
|
13
|
+
@generator = JenkinsPipelineBuilder.generator
|
14
14
|
@generator.debug = true
|
15
15
|
@generator.no_files = true
|
16
16
|
end
|
17
17
|
|
18
|
+
after :each do
|
19
|
+
JenkinsPipelineBuilder.generator.instance_variable_set(:@job_collection, {})
|
20
|
+
end
|
21
|
+
|
18
22
|
def compare_jobs(job, path)
|
19
23
|
success, xml = @generator.compile_job_to_xml(job)
|
20
24
|
expect(success).to be_true
|
@@ -86,7 +90,5 @@ describe 'Test YAML jobs conversion to XML' do
|
|
86
90
|
compare_jobs job, file_name
|
87
91
|
end
|
88
92
|
end
|
89
|
-
|
90
|
-
it 'downloads from remote repos'
|
91
93
|
end
|
92
94
|
end
|
@@ -2,18 +2,15 @@ require File.expand_path('../spec_helper', __FILE__)
|
|
2
2
|
|
3
3
|
describe 'ModuleRegistry' do
|
4
4
|
|
5
|
+
it 'needs more tests'
|
5
6
|
it 'should return item by a specified path' do
|
6
7
|
|
7
|
-
registry = JenkinsPipelineBuilder::ModuleRegistry.new
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
cc: {
|
12
|
-
dd: 'dd'
|
13
|
-
}
|
14
|
-
}
|
15
|
-
)
|
8
|
+
registry = JenkinsPipelineBuilder::ModuleRegistry.new
|
9
|
+
registry.register_job_attribute(:foo, 'jenkins name', 'desc') do
|
10
|
+
true
|
11
|
+
end
|
16
12
|
|
17
|
-
registry.
|
13
|
+
puts registry.registry.inspect
|
14
|
+
registry.get('job/foo').call.should be_true
|
18
15
|
end
|
19
16
|
end
|
@@ -2,18 +2,22 @@ require File.expand_path('../spec_helper', __FILE__)
|
|
2
2
|
|
3
3
|
describe 'Templates resolver' do
|
4
4
|
before(:each) do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@generator = JenkinsPipelineBuilder
|
5
|
+
JenkinsPipelineBuilder.credentials = {
|
6
|
+
server_ip: '127.0.0.1',
|
7
|
+
server_port: 8080,
|
8
|
+
username: 'username',
|
9
|
+
password: 'password',
|
10
|
+
log_location: '/dev/null'
|
11
|
+
}
|
12
|
+
@generator = JenkinsPipelineBuilder.generator
|
13
13
|
@generator.debug = true
|
14
14
|
@generator.no_files = true
|
15
15
|
end
|
16
16
|
|
17
|
+
after :each do
|
18
|
+
JenkinsPipelineBuilder.generator.instance_variable_set(:@job_collection, {})
|
19
|
+
end
|
20
|
+
|
17
21
|
describe 'resolving settings bags' do
|
18
22
|
it 'gives a bag when all the variables can be resolved' do
|
19
23
|
str = %(
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jenkins_pipeline_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Moochnick
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -333,10 +333,13 @@ files:
|
|
333
333
|
- lib/jenkins_pipeline_builder.rb
|
334
334
|
- lib/jenkins_pipeline_builder/builders.rb
|
335
335
|
- lib/jenkins_pipeline_builder/cli/base.rb
|
336
|
+
- lib/jenkins_pipeline_builder/cli/describe.rb
|
336
337
|
- lib/jenkins_pipeline_builder/cli/helper.rb
|
338
|
+
- lib/jenkins_pipeline_builder/cli/list.rb
|
337
339
|
- lib/jenkins_pipeline_builder/cli/pipeline.rb
|
338
340
|
- lib/jenkins_pipeline_builder/cli/view.rb
|
339
341
|
- lib/jenkins_pipeline_builder/compiler.rb
|
342
|
+
- lib/jenkins_pipeline_builder/extendable.rb
|
340
343
|
- lib/jenkins_pipeline_builder/generator.rb
|
341
344
|
- lib/jenkins_pipeline_builder/job_builder.rb
|
342
345
|
- lib/jenkins_pipeline_builder/module_registry.rb
|
@@ -402,6 +405,10 @@ files:
|
|
402
405
|
- spec/unit_tests/fixtures/files/throttle.yaml
|
403
406
|
- spec/unit_tests/fixtures/files/upstream.xml
|
404
407
|
- spec/unit_tests/fixtures/files/upstream.yaml
|
408
|
+
- spec/unit_tests/fixtures/pull_request/00.yaml
|
409
|
+
- spec/unit_tests/fixtures/pull_request/10.yaml
|
410
|
+
- spec/unit_tests/fixtures/pull_request/11.yaml
|
411
|
+
- spec/unit_tests/fixtures/pull_request/project.yaml
|
405
412
|
- spec/unit_tests/fixtures/templates/external_job.yaml
|
406
413
|
- spec/unit_tests/fixtures/templates/project_with_jobs.yaml
|
407
414
|
- spec/unit_tests/generator_spec.rb
|
@@ -486,6 +493,10 @@ test_files:
|
|
486
493
|
- spec/unit_tests/fixtures/files/throttle.yaml
|
487
494
|
- spec/unit_tests/fixtures/files/upstream.xml
|
488
495
|
- spec/unit_tests/fixtures/files/upstream.yaml
|
496
|
+
- spec/unit_tests/fixtures/pull_request/00.yaml
|
497
|
+
- spec/unit_tests/fixtures/pull_request/10.yaml
|
498
|
+
- spec/unit_tests/fixtures/pull_request/11.yaml
|
499
|
+
- spec/unit_tests/fixtures/pull_request/project.yaml
|
489
500
|
- spec/unit_tests/fixtures/templates/external_job.yaml
|
490
501
|
- spec/unit_tests/fixtures/templates/project_with_jobs.yaml
|
491
502
|
- spec/unit_tests/generator_spec.rb
|