jenkins_pipeline_builder 0.15.4 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/example/pipeline/Example-Pipeline.yaml +21 -21
- data/example/pipeline/Example-Promotion.yaml +32 -0
- data/example/pipeline/Example-Release.yaml +2 -0
- data/example/pipeline/project.yaml +2 -0
- data/jenkins_pipeline_builder.gemspec +1 -0
- data/lib/jenkins_pipeline_builder.rb +5 -0
- data/lib/jenkins_pipeline_builder/cli/describe.rb +5 -3
- data/lib/jenkins_pipeline_builder/custom_errors.rb +20 -0
- data/lib/jenkins_pipeline_builder/extension_dsl.rb +2 -2
- data/lib/jenkins_pipeline_builder/extension_set.rb +12 -5
- data/lib/jenkins_pipeline_builder/extensions.rb +7 -6
- data/lib/jenkins_pipeline_builder/extensions/build_steps.rb +93 -0
- data/lib/jenkins_pipeline_builder/extensions/helpers/build_steps/triggered_job.rb +36 -0
- data/lib/jenkins_pipeline_builder/extensions/helpers/builders/blocking_downstream_helper.rb +2 -2
- data/lib/jenkins_pipeline_builder/extensions/helpers/builders/maven3_helper.rb +2 -2
- data/lib/jenkins_pipeline_builder/extensions/helpers/extension_helper.rb +7 -7
- data/lib/jenkins_pipeline_builder/extensions/helpers/triggers/upstream_helper.rb +2 -2
- data/lib/jenkins_pipeline_builder/extensions/job_attributes.rb +60 -1
- data/lib/jenkins_pipeline_builder/extensions/promotion_conditions.rb +80 -0
- data/lib/jenkins_pipeline_builder/generator.rb +65 -57
- data/lib/jenkins_pipeline_builder/job.rb +1 -7
- data/lib/jenkins_pipeline_builder/job_collection.rb +16 -14
- data/lib/jenkins_pipeline_builder/module_registry.rb +4 -4
- data/lib/jenkins_pipeline_builder/promotion.rb +82 -0
- data/lib/jenkins_pipeline_builder/utils.rb +6 -0
- data/lib/jenkins_pipeline_builder/version.rb +1 -1
- data/lib/jenkins_pipeline_builder/view.rb +1 -4
- data/spec/lib/jenkins_pipeline_builder/extensions/build_steps_spec.rb +198 -0
- data/spec/lib/jenkins_pipeline_builder/extensions/builders_spec.rb +1 -3
- data/spec/lib/jenkins_pipeline_builder/extensions/job_attributes_spec.rb +63 -0
- data/spec/lib/jenkins_pipeline_builder/extensions/promotion_conditions_spec.rb +281 -0
- data/spec/lib/jenkins_pipeline_builder/extensions/registered_spec.rb +11 -3
- data/spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/sample_pipeline/SamplePipeline-30-Release.yaml +3 -1
- data/spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/sample_pipeline/SamplePipeline-40-Promotion.yaml +31 -0
- data/spec/lib/jenkins_pipeline_builder/fixtures/generator_tests/sample_pipeline/project.yaml +3 -1
- data/spec/lib/jenkins_pipeline_builder/fixtures/promotions_test/sample_promotion.yaml +31 -0
- data/spec/lib/jenkins_pipeline_builder/generator_spec.rb +2 -2
- data/spec/lib/jenkins_pipeline_builder/job_spec.rb +1 -19
- data/spec/lib/jenkins_pipeline_builder/promotion_spec.rb +88 -0
- data/spec/lib/jenkins_pipeline_builder/spec_helper.rb +6 -0
- metadata +86 -59
- data/lib/jenkins_pipeline_builder/project.rb +0 -26
@@ -19,7 +19,6 @@
|
|
19
19
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
20
|
# THE SOFTWARE.
|
21
21
|
#
|
22
|
-
|
23
22
|
module JenkinsPipelineBuilder
|
24
23
|
class ModuleRegistry
|
25
24
|
attr_accessor :registry, :registered_modules
|
@@ -52,7 +51,9 @@ module JenkinsPipelineBuilder
|
|
52
51
|
builders: '//builders',
|
53
52
|
publishers: '//publishers',
|
54
53
|
wrappers: '//buildWrappers',
|
55
|
-
triggers: '//triggers'
|
54
|
+
triggers: '//triggers',
|
55
|
+
build_steps: '//buildSteps',
|
56
|
+
promotion_conditions: '//conditions'
|
56
57
|
}
|
57
58
|
end
|
58
59
|
|
@@ -77,7 +78,6 @@ module JenkinsPipelineBuilder
|
|
77
78
|
def get_by_path_collection(path, registry)
|
78
79
|
item = registry[path.shift.to_sym]
|
79
80
|
return item if path.count == 0
|
80
|
-
|
81
81
|
get_by_path_collection(path, item)
|
82
82
|
end
|
83
83
|
|
@@ -90,7 +90,7 @@ module JenkinsPipelineBuilder
|
|
90
90
|
params.each do |key, value|
|
91
91
|
next unless registry.is_a? Hash
|
92
92
|
unless registry.key? key
|
93
|
-
raise "!!!! could not find key #{key} !!!!" if strict
|
93
|
+
raise TypeError, "!!!! could not find key #{key} !!!!" if strict
|
94
94
|
next
|
95
95
|
end
|
96
96
|
reg_value = registry[key]
|
@@ -0,0 +1,82 @@
|
|
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 Promotion
|
25
|
+
def initialize(generator)
|
26
|
+
@generator = generator
|
27
|
+
@client = generator.client
|
28
|
+
@logger = @client.logger
|
29
|
+
end
|
30
|
+
|
31
|
+
def create(params, job_name)
|
32
|
+
success, payload = prom_to_xml(params)
|
33
|
+
return success, payload unless success
|
34
|
+
xml = payload
|
35
|
+
return local_output(xml) if JenkinsPipelineBuilder.debug || JenkinsPipelineBuilder.file_mode
|
36
|
+
|
37
|
+
@client.get_config(get_process_path(job_name, params[:name]))
|
38
|
+
@client.post_config(set_process_path(job_name, params[:name]), xml)
|
39
|
+
rescue JenkinsApi::Exceptions::NotFound
|
40
|
+
@client.post_config(init_process_path(job_name, params[:name]), xml)
|
41
|
+
end
|
42
|
+
|
43
|
+
def prom_to_xml(params)
|
44
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
45
|
+
xml.send('hudson.plugins.promoted__builds.PromotionProcess', 'plugin' => 'promoted-builds@2.27') do
|
46
|
+
xml.buildSteps
|
47
|
+
xml.conditions
|
48
|
+
end
|
49
|
+
end
|
50
|
+
@n_xml = builder.doc
|
51
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
52
|
+
[true, @n_xml.to_xml]
|
53
|
+
end
|
54
|
+
|
55
|
+
def local_output(xml)
|
56
|
+
JenkinsPipelineBuilder.logger.info 'Will create promotion'
|
57
|
+
JenkinsPipelineBuilder.logger.info xml.to_s if @debug
|
58
|
+
xml.to_s if @debug
|
59
|
+
FileUtils.mkdir_p(out_dir) unless File.exist?(out_dir)
|
60
|
+
File.open("#{out_dir}/promotion_debug.xml", 'w') { |f| f.write xml }
|
61
|
+
xml
|
62
|
+
end
|
63
|
+
|
64
|
+
def out_dir
|
65
|
+
'out/xml'
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def init_process_path(job_name, process_name)
|
71
|
+
"/job/#{URI.encode job_name}/promotion/createProcess?name=#{URI.encode process_name}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_process_path(job_name, process_name)
|
75
|
+
"/job/#{URI.encode job_name}/promotion/process/#{URI.encode process_name}/config.xml"
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_process_path(job_name, process_name)
|
79
|
+
"/job/#{URI.encode job_name}/promotion/process/#{URI.encode process_name}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -40,6 +40,12 @@ module JenkinsPipelineBuilder
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
def self.symbolize_with_empty_hash!(array_of_maybe_str)
|
44
|
+
array_of_maybe_str.map! do |maybe_str|
|
45
|
+
maybe_str.is_a?(String) ? { maybe_str.to_sym => {} } : maybe_str
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
43
49
|
def self.hash_merge!(old_hash, new_hash)
|
44
50
|
old_hash.merge!(new_hash) do |_key, old, new|
|
45
51
|
if old.is_a?(Hash) && new.is_a?(Hash)
|
@@ -72,10 +72,7 @@ module JenkinsPipelineBuilder
|
|
72
72
|
create_base_view(params[:name], params[:type], params[:parent_view])
|
73
73
|
@logger.debug "Creating a #{params[:type]} view with params: #{params.inspect}"
|
74
74
|
|
75
|
-
if JenkinsPipelineBuilder.debug
|
76
|
-
# pp post_params(params)
|
77
|
-
return
|
78
|
-
end
|
75
|
+
return if JenkinsPipelineBuilder.debug
|
79
76
|
|
80
77
|
view_path = params[:parent_view].nil? ? '' : "/view/#{params[:parent_view]}"
|
81
78
|
view_path += "/view/#{params[:name]}/configSubmit"
|
@@ -0,0 +1,198 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe 'build_steps' do
|
4
|
+
after :each do
|
5
|
+
JenkinsPipelineBuilder.registry.clear_versions
|
6
|
+
end
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
JenkinsPipelineBuilder.credentials = {
|
10
|
+
server_ip: '127.0.0.1',
|
11
|
+
server_port: 8080,
|
12
|
+
username: 'username',
|
13
|
+
password: 'password',
|
14
|
+
log_location: '/dev/null'
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
before :each do
|
19
|
+
builder = Nokogiri::XML::Builder.new { |xml| xml.buildSteps }
|
20
|
+
@n_xml = builder.doc
|
21
|
+
end
|
22
|
+
|
23
|
+
after :each do |example|
|
24
|
+
name = example.description.tr ' ', '_'
|
25
|
+
require 'fileutils'
|
26
|
+
FileUtils.mkdir_p 'out/xml'
|
27
|
+
File.open("./out/xml/build_steps_#{name}.xml", 'w') { |f| @n_xml.write_xml_to f }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'generic' do
|
31
|
+
it 'can register a build_step' do
|
32
|
+
result = build_step do
|
33
|
+
name :test_generic
|
34
|
+
plugin_id :foo
|
35
|
+
xml do
|
36
|
+
foo :bar
|
37
|
+
end
|
38
|
+
end
|
39
|
+
JenkinsPipelineBuilder.registry.registry[:job][:build_steps].delete :test_generic
|
40
|
+
expect(result).to be true
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'fails to register an invalid build_step' do
|
44
|
+
result = build_step do
|
45
|
+
name :test_generic
|
46
|
+
end
|
47
|
+
JenkinsPipelineBuilder.registry.registry[:job][:build_steps].delete :test_generic
|
48
|
+
expect(result).to be false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'triggered_jobs' do
|
53
|
+
before :each do
|
54
|
+
allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
|
55
|
+
list_installed: { 'promoted-builds' => '2.31', 'parameterized-trigger' => '20.0' }
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'generates a configuration with standard defaults' do
|
60
|
+
params = { build_steps: { triggered_job:
|
61
|
+
{ name: 'ReleaseBuild' } } }
|
62
|
+
|
63
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
64
|
+
|
65
|
+
xml_from_jenkins = parse_expectation_xml(
|
66
|
+
"<buildSteps>
|
67
|
+
<hudson.plugins.parameterizedtrigger.TriggerBuilder plugin='parameterized-trigger@2.31'>
|
68
|
+
<configs>
|
69
|
+
<hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>
|
70
|
+
<configs class='empty-list' />
|
71
|
+
<projects>ReleaseBuild</projects>
|
72
|
+
<condition>ALWAYS</condition>
|
73
|
+
<triggerWithNoParameters>false</triggerWithNoParameters>
|
74
|
+
<block>
|
75
|
+
<buildStepFailureThreshold>
|
76
|
+
<name>FAILURE</name>
|
77
|
+
<ordinal>2</ordinal>
|
78
|
+
<color>RED</color>
|
79
|
+
<completeBuild>true</completeBuild>
|
80
|
+
</buildStepFailureThreshold>
|
81
|
+
<unstableThreshold>
|
82
|
+
<name>UNSTABLE</name>
|
83
|
+
<ordinal>1</ordinal>
|
84
|
+
<color>YELLOW</color>
|
85
|
+
<completeBuild>true</completeBuild>
|
86
|
+
</unstableThreshold>
|
87
|
+
<failureThreshold>
|
88
|
+
<name>FAILURE</name>
|
89
|
+
<ordinal>2</ordinal>
|
90
|
+
<color>RED</color>
|
91
|
+
<completeBuild>true</completeBuild>
|
92
|
+
</failureThreshold>
|
93
|
+
</block>
|
94
|
+
<buildAllNodesWithLabel>false</buildAllNodesWithLabel>
|
95
|
+
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>
|
96
|
+
</configs>
|
97
|
+
</hudson.plugins.parameterizedtrigger.TriggerBuilder>
|
98
|
+
</buildSteps>"
|
99
|
+
)
|
100
|
+
|
101
|
+
expect(@n_xml).to be_equivalent_to(xml_from_jenkins)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'generates no block conditions when set to false' do
|
105
|
+
params = { build_steps: { triggered_job:
|
106
|
+
{ name: 'ReleaseBuild', block_condition: false } } }
|
107
|
+
|
108
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
109
|
+
|
110
|
+
xml_from_jenkins = parse_expectation_xml(
|
111
|
+
"<buildSteps>
|
112
|
+
<hudson.plugins.parameterizedtrigger.TriggerBuilder plugin='parameterized-trigger@2.31'>
|
113
|
+
<configs>
|
114
|
+
<hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>
|
115
|
+
<configs class='empty-list'/>
|
116
|
+
<projects>ReleaseBuild</projects>
|
117
|
+
<condition>ALWAYS</condition>
|
118
|
+
<triggerWithNoParameters>false</triggerWithNoParameters>
|
119
|
+
<buildAllNodesWithLabel>false</buildAllNodesWithLabel>
|
120
|
+
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>
|
121
|
+
</configs>
|
122
|
+
</hudson.plugins.parameterizedtrigger.TriggerBuilder>
|
123
|
+
</buildSteps>"
|
124
|
+
)
|
125
|
+
|
126
|
+
expect(@n_xml).to be_equivalent_to(xml_from_jenkins)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'generates build state with current parameters' do
|
130
|
+
params = { build_steps: { triggered_job:
|
131
|
+
{ name: 'ReleaseBuild', build_parameters: [:current] } } }
|
132
|
+
|
133
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
134
|
+
|
135
|
+
expect(@n_xml
|
136
|
+
.at_xpath("//buildSteps/
|
137
|
+
hudson.plugins.parameterizedtrigger.TriggerBuilder/
|
138
|
+
configs/
|
139
|
+
hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig/
|
140
|
+
configs/
|
141
|
+
hudson.plugins.parameterizedtrigger.CurrentBuildParameters"))
|
142
|
+
.not_to equal(nil)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'generates build state with predefined parameters' do
|
146
|
+
params = { build_steps: { triggered_job:
|
147
|
+
{ name: 'ReleaseBuild', build_parameters: [[:predefined, { x: 1, 'y' => 2 }]] } } }
|
148
|
+
|
149
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
150
|
+
|
151
|
+
expect(@n_xml
|
152
|
+
.at_xpath("//buildSteps/
|
153
|
+
hudson.plugins.parameterizedtrigger.TriggerBuilder/
|
154
|
+
configs/
|
155
|
+
hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig/
|
156
|
+
configs/
|
157
|
+
hudson.plugins.parameterizedtrigger.PredefinedBuildParameters/
|
158
|
+
properties").text)
|
159
|
+
.to eq('X=1 Y=2')
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'generates build state with file parameters' do
|
163
|
+
params = { build_steps: { triggered_job:
|
164
|
+
{ name: 'ReleaseBuild', build_parameters: [[:file, '/usr/local/params']] } } }
|
165
|
+
|
166
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
167
|
+
|
168
|
+
expect(@n_xml
|
169
|
+
.at_xpath("//buildSteps/
|
170
|
+
hudson.plugins.parameterizedtrigger.TriggerBuilder/
|
171
|
+
configs/
|
172
|
+
hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig/
|
173
|
+
configs/
|
174
|
+
hudson.plugins.parameterizedtrigger.FileBuildParameters/
|
175
|
+
propertiesFile").text)
|
176
|
+
.to eq('/usr/local/params')
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'keep_builds_forever' do
|
181
|
+
before :each do
|
182
|
+
allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
|
183
|
+
list_installed: { 'promoted-builds' => '2.31' }
|
184
|
+
)
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'generates the keep_builds_forever tag' do
|
188
|
+
params = { build_steps: { keep_builds_forever: true } }
|
189
|
+
|
190
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
191
|
+
|
192
|
+
expect(@n_xml
|
193
|
+
.at_xpath("//buildSteps/
|
194
|
+
hudson.plugins.promoted__builds.KeepBuildForeverAction"))
|
195
|
+
.to_not eq(nil)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -55,11 +55,10 @@ describe 'builders' do
|
|
55
55
|
list_installed: { 'jenkins-multijob-plugin' => '20.0' }
|
56
56
|
)
|
57
57
|
end
|
58
|
+
|
58
59
|
it 'generates a configuration' do
|
59
60
|
params = { builders: { multi_job: { phases: { foo: { jobs: [{ name: 'foo' }] } } } } }
|
60
|
-
|
61
61
|
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
62
|
-
|
63
62
|
builder = @n_xml.root.children.first
|
64
63
|
expect(builder.name).to match 'com.tikal.jenkins.plugins.multijob.MultiJobBuilder'
|
65
64
|
end
|
@@ -115,7 +114,6 @@ describe 'builders' do
|
|
115
114
|
|
116
115
|
context 'step failure threshold' do
|
117
116
|
let(:params) { { builders: { blocking_downstream: { fail: 'FAILURE' } } } }
|
118
|
-
|
119
117
|
it 'generates a configuration' do
|
120
118
|
expect(@n_xml.root.css('buildStepFailureThreshold').first).to_not be_nil
|
121
119
|
expect(@n_xml.root.css('buildStepFailureThreshold').first.css('color').first.text).to eq 'RED'
|
@@ -144,6 +144,69 @@ describe 'job_attributes' do
|
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
|
+
context 'block_when_downstream_building' do
|
148
|
+
it 'sets blockBuildWhenDownstreamBuilding' do
|
149
|
+
params = { block_when_downstream_building: 'true' }
|
150
|
+
|
151
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
152
|
+
xml.send('hudson.plugins.promoted__builds.PromotionProcess', 'plugin' => 'promoted-builds@2.27')
|
153
|
+
end
|
154
|
+
@n_xml = builder.doc
|
155
|
+
|
156
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
157
|
+
|
158
|
+
expect(@n_xml.at('blockBuildWhenDownstreamBuilding')).to be_truthy
|
159
|
+
expect(@n_xml.at('blockBuildWhenDownstreamBuilding').content).to eq 'true'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'block_when_upstream_building' do
|
164
|
+
it 'sets blockBuildWhenUpstreamBuilding' do
|
165
|
+
params = { block_when_upstream_building: 'true' }
|
166
|
+
|
167
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
168
|
+
xml.send('hudson.plugins.promoted__builds.PromotionProcess', 'plugin' => 'promoted-builds@2.27')
|
169
|
+
end
|
170
|
+
@n_xml = builder.doc
|
171
|
+
|
172
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
173
|
+
|
174
|
+
expect(@n_xml.at('blockBuildWhenUpstreamBuilding')).to be_truthy
|
175
|
+
expect(@n_xml.at('blockBuildWhenUpstreamBuilding').content).to eq 'true'
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'is_visible' do
|
180
|
+
it 'sets isVisible' do
|
181
|
+
params = { is_visible: 'true' }
|
182
|
+
|
183
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
184
|
+
xml.send('hudson.plugins.promoted__builds.PromotionProcess', 'plugin' => 'promoted-builds@2.27')
|
185
|
+
end
|
186
|
+
@n_xml = builder.doc
|
187
|
+
|
188
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
189
|
+
|
190
|
+
expect(@n_xml.at('isVisible')).to be_truthy
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'promotion_icon' do
|
195
|
+
it 'sets the promotion_icon' do
|
196
|
+
params = { promotion_icon: 'gold-e' }
|
197
|
+
|
198
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
199
|
+
xml.send('hudson.plugins.promoted__builds.PromotionProcess', 'plugin' => 'promoted-builds@2.27')
|
200
|
+
end
|
201
|
+
@n_xml = builder.doc
|
202
|
+
|
203
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
204
|
+
|
205
|
+
expect(@n_xml.at('icon')).to be_truthy
|
206
|
+
expect(@n_xml.at('icon').content).to eq 'star-gold-e'
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
147
210
|
context 'scm params' do
|
148
211
|
before :each do
|
149
212
|
builder = Nokogiri::XML::Builder.new { |xml| xml.scm }
|
@@ -0,0 +1,281 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe 'promotion_conditions' do
|
4
|
+
after :each do
|
5
|
+
JenkinsPipelineBuilder.registry.clear_versions
|
6
|
+
end
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
JenkinsPipelineBuilder.credentials = {
|
10
|
+
server_ip: '127.0.0.1',
|
11
|
+
server_port: 8080,
|
12
|
+
username: 'username',
|
13
|
+
password: 'password',
|
14
|
+
log_location: '/dev/null'
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
before :each do
|
19
|
+
condition = Nokogiri::XML::Builder.new { |xml| xml.conditions }
|
20
|
+
@n_xml = condition.doc
|
21
|
+
end
|
22
|
+
|
23
|
+
after :each do |example|
|
24
|
+
name = example.description.tr ' ', '_'
|
25
|
+
require 'fileutils'
|
26
|
+
FileUtils.mkdir_p 'out/xml'
|
27
|
+
File.open("./out/xml/conditions_#{name}.xml", 'w') { |f| @n_xml.write_xml_to f }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'generic' do
|
31
|
+
it 'can register a condition' do
|
32
|
+
result = promotion_condition do
|
33
|
+
name :test_generic
|
34
|
+
plugin_id :foo
|
35
|
+
xml do
|
36
|
+
foo :bar
|
37
|
+
end
|
38
|
+
end
|
39
|
+
JenkinsPipelineBuilder.registry.registry[:job][:promotion_conditions].delete :test_generic
|
40
|
+
expect(result).to be true
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'fails to register an invalid condition' do
|
44
|
+
result = promotion_condition do
|
45
|
+
name :test_generic
|
46
|
+
end
|
47
|
+
JenkinsPipelineBuilder.registry.registry[:job][:promotion_conditions].delete :test_generic
|
48
|
+
expect(result).to be false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'type: manual' do
|
53
|
+
before :each do
|
54
|
+
allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
|
55
|
+
list_installed: { 'promoted-builds' => '2.31' }
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'generates manual given parameter' do
|
60
|
+
params = { promotion_conditions:
|
61
|
+
[{ manual: { users: 'unauthorized' } }] }
|
62
|
+
|
63
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
64
|
+
|
65
|
+
expect(@n_xml
|
66
|
+
.at('//hudson.plugins.promoted__builds.conditions.ManualCondition/users')
|
67
|
+
.text)
|
68
|
+
.to eq('unauthorized')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'generates manual defaults' do
|
72
|
+
params = { promotion_conditions:
|
73
|
+
[{ manual: {} }] }
|
74
|
+
|
75
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
76
|
+
|
77
|
+
expect(@n_xml
|
78
|
+
.at('//hudson.plugins.promoted__builds.conditions.ManualCondition/users')
|
79
|
+
.text)
|
80
|
+
.to eq('')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'type: self_promotion' do
|
85
|
+
before :each do
|
86
|
+
allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
|
87
|
+
list_installed: { 'promoted-builds' => '2.31' }
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'generates a self promotion given parameters' do
|
92
|
+
params = { promotion_conditions:
|
93
|
+
[{ self_promotion:
|
94
|
+
{ even_if_unstable: false } }] }
|
95
|
+
|
96
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
97
|
+
|
98
|
+
expect(@n_xml
|
99
|
+
.at('//hudson.plugins.promoted__builds.conditions.SelfPromotionCondition/evenIfUnstable')
|
100
|
+
.text)
|
101
|
+
.to eq('false')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'generates a self promotion defaults' do
|
105
|
+
params = { promotion_conditions: [{ self_promotion: {} }] }
|
106
|
+
|
107
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
108
|
+
|
109
|
+
expect(@n_xml
|
110
|
+
.at('//hudson.plugins.promoted__builds.conditions.SelfPromotionCondition/evenIfUnstable')
|
111
|
+
.text)
|
112
|
+
.to eq('true')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'type: parameterized_self_promotion' do
|
117
|
+
before :each do
|
118
|
+
allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
|
119
|
+
list_installed: { 'promoted-builds' => '2.31' }
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'generates a parameterized self promotion given parameters' do
|
124
|
+
params = { promotion_conditions:
|
125
|
+
[{ parameterized_self_promotion:
|
126
|
+
{ parameter_name: 'SOME_ENV_CHAR', parameter_value: false, even_if_unstable: false } }] }
|
127
|
+
|
128
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
129
|
+
|
130
|
+
expect(@n_xml
|
131
|
+
.at('//hudson.plugins.promoted__builds.conditions.ParameterizedSelfPromotionCondition/parameterName')
|
132
|
+
.text)
|
133
|
+
.to eq('SOME_ENV_CHAR')
|
134
|
+
expect(@n_xml
|
135
|
+
.at('//hudson.plugins.promoted__builds.conditions.ParameterizedSelfPromotionCondition/parameterValue')
|
136
|
+
.text)
|
137
|
+
.to eq('false')
|
138
|
+
expect(@n_xml
|
139
|
+
.at('//hudson.plugins.promoted__builds.conditions.ParameterizedSelfPromotionCondition/evenIfUnstable')
|
140
|
+
.text)
|
141
|
+
.to eq('false')
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'generates a parameterized self promotion defaults' do
|
145
|
+
params = { promotion_conditions:
|
146
|
+
[{ parameterized_self_promotion: {} }] }
|
147
|
+
|
148
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
149
|
+
|
150
|
+
expect(@n_xml
|
151
|
+
.at('//hudson.plugins.promoted__builds.conditions.ParameterizedSelfPromotionCondition/parameterName')
|
152
|
+
.text)
|
153
|
+
.to eq('')
|
154
|
+
expect(@n_xml
|
155
|
+
.at('//hudson.plugins.promoted__builds.conditions.ParameterizedSelfPromotionCondition/parameterValue')
|
156
|
+
.text).to eq('true')
|
157
|
+
expect(@n_xml
|
158
|
+
.at('//hudson.plugins.promoted__builds.conditions.ParameterizedSelfPromotionCondition/evenIfUnstable')
|
159
|
+
.text)
|
160
|
+
.to eq('true')
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'type: downstream_pass' do
|
165
|
+
before :each do
|
166
|
+
allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
|
167
|
+
list_installed: { 'promoted-builds' => '2.31' }
|
168
|
+
)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'generates a downstream pass configuration given parameters' do
|
172
|
+
params = { promotion_conditions:
|
173
|
+
[downstream_pass:
|
174
|
+
{ jobs: 'Worst-Commit-Ever', even_if_unstable: true }] }
|
175
|
+
|
176
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
177
|
+
|
178
|
+
expect(@n_xml
|
179
|
+
.at('//hudson.plugins.promoted__builds.conditions.DownstreamPassCondition/jobs')
|
180
|
+
.text)
|
181
|
+
.to eq('Worst-Commit-Ever')
|
182
|
+
expect(@n_xml
|
183
|
+
.at('//hudson.plugins.promoted__builds.conditions.DownstreamPassCondition/evenIfUnstable')
|
184
|
+
.text)
|
185
|
+
.to eq('true')
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'generates a downstream pass defaults' do
|
189
|
+
params = { promotion_conditions:
|
190
|
+
[downstream_pass: {}] }
|
191
|
+
|
192
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
193
|
+
|
194
|
+
expect(@n_xml
|
195
|
+
.at('//hudson.plugins.promoted__builds.conditions.DownstreamPassCondition/jobs')
|
196
|
+
.text)
|
197
|
+
.to eq('{{Example}}-Commit')
|
198
|
+
expect(@n_xml
|
199
|
+
.at('//hudson.plugins.promoted__builds.conditions.DownstreamPassCondition/evenIfUnstable')
|
200
|
+
.text)
|
201
|
+
.to eq('true')
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'type: upstream_promotion' do
|
206
|
+
before :each do
|
207
|
+
allow(JenkinsPipelineBuilder.client).to receive(:plugin).and_return double(
|
208
|
+
list_installed: { 'promoted-builds' => '2.31' }
|
209
|
+
)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'generates a upstream promotion parameters' do
|
213
|
+
params = { promotion_conditions:
|
214
|
+
[upstream_promotion:
|
215
|
+
{ promotion_name: 'Never-Promotes' }] }
|
216
|
+
|
217
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
218
|
+
|
219
|
+
expect(@n_xml
|
220
|
+
.at('//hudson.plugins.promoted__builds.conditions.UpstreamPromotionCondition/promotionName')
|
221
|
+
.text)
|
222
|
+
.to eq('Never-Promotes')
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'generates a upstream promotion defaults' do
|
226
|
+
params = { promotion_conditions:
|
227
|
+
[upstream_promotion: {}] }
|
228
|
+
|
229
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
230
|
+
|
231
|
+
expect(@n_xml
|
232
|
+
.at('//hudson.plugins.promoted__builds.conditions.UpstreamPromotionCondition/promotionName')
|
233
|
+
.text)
|
234
|
+
.to eq('01. Staging Promotion')
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'generates all condition defaults given no parameters' do
|
238
|
+
params = { promotion_conditions:
|
239
|
+
[{ manual: {} },
|
240
|
+
{ self_promotion: {} },
|
241
|
+
{ parameterized_self_promotion: {} },
|
242
|
+
{ downstream_pass: {} },
|
243
|
+
{ upstream_promotion: {} }] }
|
244
|
+
|
245
|
+
JenkinsPipelineBuilder.registry.traverse_registry_path('job', params, @n_xml)
|
246
|
+
|
247
|
+
expect(@n_xml
|
248
|
+
.at('//hudson.plugins.promoted__builds.conditions.ManualCondition/users')
|
249
|
+
.text)
|
250
|
+
.to eq('')
|
251
|
+
expect(@n_xml
|
252
|
+
.at('//hudson.plugins.promoted__builds.conditions.SelfPromotionCondition/evenIfUnstable')
|
253
|
+
.text)
|
254
|
+
.to eq('true')
|
255
|
+
expect(@n_xml
|
256
|
+
.at('//hudson.plugins.promoted__builds.conditions.ParameterizedSelfPromotionCondition/parameterName')
|
257
|
+
.text)
|
258
|
+
.to eq('')
|
259
|
+
expect(@n_xml
|
260
|
+
.at('//hudson.plugins.promoted__builds.conditions.ParameterizedSelfPromotionCondition/parameterValue')
|
261
|
+
.text)
|
262
|
+
.to eq('true')
|
263
|
+
expect(@n_xml
|
264
|
+
.at('//hudson.plugins.promoted__builds.conditions.ParameterizedSelfPromotionCondition/evenIfUnstable')
|
265
|
+
.text)
|
266
|
+
.to eq('true')
|
267
|
+
expect(@n_xml
|
268
|
+
.at('//hudson.plugins.promoted__builds.conditions.DownstreamPassCondition/jobs')
|
269
|
+
.text)
|
270
|
+
.to eq('{{Example}}-Commit')
|
271
|
+
expect(@n_xml
|
272
|
+
.at('//hudson.plugins.promoted__builds.conditions.DownstreamPassCondition/evenIfUnstable')
|
273
|
+
.text)
|
274
|
+
.to eq('true')
|
275
|
+
expect(@n_xml
|
276
|
+
.at('//hudson.plugins.promoted__builds.conditions.UpstreamPromotionCondition/promotionName')
|
277
|
+
.text)
|
278
|
+
.to eq('01. Staging Promotion')
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|