jenkins_pipeline_builder 0.4.2 → 0.5.0
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 +65 -0
- data/LICENSE +1 -1
- data/README.md +64 -2
- data/Rakefile +13 -11
- data/bin/generate +2 -4
- data/jenkins_pipeline_builder.gemspec +14 -11
- data/lib/jenkins_pipeline_builder.rb +2 -1
- data/lib/jenkins_pipeline_builder/builders.rb +89 -33
- data/lib/jenkins_pipeline_builder/cli/base.rb +21 -29
- data/lib/jenkins_pipeline_builder/cli/helper.rb +12 -15
- data/lib/jenkins_pipeline_builder/cli/pipeline.rb +6 -1
- data/lib/jenkins_pipeline_builder/cli/view.rb +2 -2
- data/lib/jenkins_pipeline_builder/compiler.rb +58 -56
- data/lib/jenkins_pipeline_builder/generator.rb +362 -172
- data/lib/jenkins_pipeline_builder/job_builder.rb +48 -45
- data/lib/jenkins_pipeline_builder/module_registry.rb +4 -6
- data/lib/jenkins_pipeline_builder/publishers.rb +53 -38
- data/lib/jenkins_pipeline_builder/pull_request.rb +156 -0
- data/lib/jenkins_pipeline_builder/triggers.rb +24 -25
- data/lib/jenkins_pipeline_builder/utils.rb +13 -7
- data/lib/jenkins_pipeline_builder/version.rb +2 -2
- data/lib/jenkins_pipeline_builder/view.rb +120 -98
- data/lib/jenkins_pipeline_builder/wrappers.rb +44 -44
- data/lib/jenkins_pipeline_builder/xml_helper.rb +4 -4
- data/spec/func_tests/spec_helper.rb +2 -2
- data/spec/func_tests/view_spec.rb +6 -6
- data/spec/unit_tests/compiler_spec.rb +7 -7
- data/spec/unit_tests/fixtures/files/Job-Gem-Build.xml +2 -2
- data/spec/unit_tests/fixtures/files/Job-Gem-Build.yaml +1 -0
- data/spec/unit_tests/fixtures/files/concurrent_build.xml +17 -0
- data/spec/unit_tests/fixtures/files/concurrent_build.yaml +4 -0
- data/spec/unit_tests/fixtures/files/downstream_blocking.xml +19 -0
- data/spec/unit_tests/fixtures/files/downstream_blocking.yaml +15 -0
- data/spec/unit_tests/fixtures/files/groovy_postbuild.xml +29 -0
- data/spec/unit_tests/fixtures/files/groovy_postbuild.yaml +9 -0
- data/spec/unit_tests/generator_spec.rb +30 -25
- data/spec/unit_tests/module_registry_spec.rb +9 -9
- data/spec/unit_tests/resolve_dependencies_spec.rb +108 -89
- data/spec/unit_tests/spec_helper.rb +1 -1
- metadata +62 -4
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2014
|
2
|
+
# Copyright (c) 2014 Constant Contact
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -25,12 +25,12 @@ module JenkinsPipelineBuilder
|
|
25
25
|
def self.update_node_text(n_xml, path, value)
|
26
26
|
n_node = n_xml.xpath(path).first
|
27
27
|
if n_node.nil?
|
28
|
-
left, right = path.match(
|
28
|
+
left, right = path.match(%r{^(.*)/([^/]*)$}).captures
|
29
29
|
parent_node = n_xml.xpath(left).first
|
30
30
|
Nokogiri::XML::Builder.with(parent_node) do |xml|
|
31
|
-
xml.send(right)
|
31
|
+
xml.send(right) do
|
32
32
|
xml.text value
|
33
|
-
|
33
|
+
end
|
34
34
|
end
|
35
35
|
else
|
36
36
|
n_node.content = value
|
@@ -4,14 +4,14 @@ require 'rspec'
|
|
4
4
|
require 'simplecov'
|
5
5
|
require 'simplecov-rcov'
|
6
6
|
|
7
|
-
SimpleCov.start if ENV[
|
7
|
+
SimpleCov.start if ENV['COVERAGE']
|
8
8
|
|
9
9
|
require File.expand_path('../../../lib/jenkins_pipeline_builder', __FILE__)
|
10
10
|
|
11
11
|
RSpec.configure do |config|
|
12
12
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
13
|
config.run_all_when_everything_filtered = true
|
14
|
-
config.filter_run_excluding :
|
14
|
+
config.filter_run_excluding broken: true
|
15
15
|
|
16
16
|
config.before(:each) do
|
17
17
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path('../spec_helper', __FILE__)
|
2
2
|
|
3
3
|
describe JenkinsPipelineBuilder::View do
|
4
|
-
context
|
4
|
+
context 'With properly initialized client' do
|
5
5
|
before(:all) do
|
6
6
|
@creds_file = '~/.jenkins_api_client/login.yml'
|
7
7
|
@valid_post_responses = [200, 201, 302]
|
@@ -10,9 +10,9 @@ describe JenkinsPipelineBuilder::View do
|
|
10
10
|
YAML.load_file(File.expand_path(@creds_file, __FILE__))
|
11
11
|
)
|
12
12
|
@client.logger.level = Logger::DEBUG
|
13
|
-
@generator = JenkinsPipelineBuilder::Generator.new(
|
13
|
+
@generator = JenkinsPipelineBuilder::Generator.new(@client)
|
14
14
|
@generator.no_files = true
|
15
|
-
rescue
|
15
|
+
rescue StandardError => e
|
16
16
|
puts 'WARNING: Credentials are not set properly.'
|
17
17
|
puts e.message
|
18
18
|
end
|
@@ -43,7 +43,7 @@ describe JenkinsPipelineBuilder::View do
|
|
43
43
|
|
44
44
|
it 'accepts the name of the view and creates the view' do
|
45
45
|
params = {
|
46
|
-
:
|
46
|
+
name: 'test_list_view'
|
47
47
|
}
|
48
48
|
|
49
49
|
test_and_validate(params)
|
@@ -76,10 +76,10 @@ describe JenkinsPipelineBuilder::View do
|
|
76
76
|
groupingRules: [{
|
77
77
|
groupRegex: 'Step-1.*',
|
78
78
|
namingRule: '1. Commit'
|
79
|
-
},{
|
79
|
+
}, {
|
80
80
|
groupRegex: 'Step-2.*',
|
81
81
|
namingRule: '2. Acceptance'
|
82
|
-
},{
|
82
|
+
}, {
|
83
83
|
groupRegex: 'Step-3.*',
|
84
84
|
namingRule: '3. Release'
|
85
85
|
}]
|
@@ -3,13 +3,13 @@ require File.expand_path('../spec_helper', __FILE__)
|
|
3
3
|
describe 'Compiler' do
|
4
4
|
it 'transforms hash into hash' do
|
5
5
|
hash = {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
a: 'A sentence',
|
7
|
+
b: 'B sentence',
|
8
|
+
hash: {
|
9
|
+
c: 5,
|
10
|
+
d: true
|
11
|
+
},
|
12
|
+
z: false
|
13
13
|
}
|
14
14
|
|
15
15
|
success, result = JenkinsPipelineBuilder::Compiler.compile(hash)
|
@@ -105,7 +105,7 @@
|
|
105
105
|
</details>
|
106
106
|
<deployPattern>pkg/*.gem</deployPattern>
|
107
107
|
<resolvePattern/>
|
108
|
-
<matrixParams
|
108
|
+
<matrixParams>foo=bar</matrixParams>
|
109
109
|
<deployBuildInfo>true</deployBuildInfo>
|
110
110
|
<includeEnvVars>false</includeEnvVars>
|
111
111
|
<envVarsPatterns>
|
@@ -139,4 +139,4 @@
|
|
139
139
|
</ruby-object>
|
140
140
|
</ruby-proxy-object>
|
141
141
|
</buildWrappers>
|
142
|
-
</project>
|
142
|
+
</project>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project>
|
3
|
+
<actions/>
|
4
|
+
<description>Testing concurrent build setting</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>true</concurrentBuild>
|
14
|
+
<builders/>
|
15
|
+
<publishers/>
|
16
|
+
<buildWrappers/>
|
17
|
+
</project>
|
@@ -0,0 +1,19 @@
|
|
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><hudson.plugins.parameterizedtrigger.TriggerBuilder plugin="parameterized-trigger"><configs><hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig><configs><hudson.plugins.parameterizedtrigger.PredefinedBuildParameters><properties>param1
|
15
|
+
param2
|
16
|
+
</properties></hudson.plugins.parameterizedtrigger.PredefinedBuildParameters></configs><projects>downstream</projects><condition>FAILURE</condition><triggerWithNoParameters>false</triggerWithNoParameters><block><buildStepFailureThreshold><name>FAILURE</name><ordinal>2</ordinal><color>RED</color><completeBuild>true</completeBuild></buildStepFailureThreshold><failureThreshold><name>SUCCESS</name><ordinal>0</ordinal><color>BLUE</color><completeBuild>true</completeBuild></failureThreshold><unstableThreshold><name>UNSTABLE</name><ordinal>1</ordinal><color>YELLOW</color><completeBuild>true</completeBuild></unstableThreshold></block><buildAllNodesWithLabel>false</buildAllNodesWithLabel></hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig></configs></hudson.plugins.parameterizedtrigger.TriggerBuilder></builders>
|
17
|
+
<publishers/>
|
18
|
+
<buildWrappers/>
|
19
|
+
</project>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
- job:
|
3
|
+
name: downstream_blocking
|
4
|
+
builders:
|
5
|
+
- blocking_downstream:
|
6
|
+
project: downstream
|
7
|
+
data:
|
8
|
+
- params: |
|
9
|
+
param1
|
10
|
+
param2
|
11
|
+
condition: FAILURE
|
12
|
+
trigger_with_no_parameters: false
|
13
|
+
fail: FAILURE
|
14
|
+
mark_fail: SUCCESS
|
15
|
+
mark_unstable: UNSTABLE
|
@@ -0,0 +1,29 @@
|
|
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/>
|
15
|
+
<publishers>
|
16
|
+
<org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder plugin="groovy-postbuild">
|
17
|
+
<groovyScript>manager.listener.logger.println "Testing Groovy Postbuild: ${manager.build.result}"</groovyScript>
|
18
|
+
<behavior>0</behavior>
|
19
|
+
<runFormMatrixParent>false</runFormMatrixParent>
|
20
|
+
<org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
21
|
+
<path>/test</path>
|
22
|
+
</org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
23
|
+
<org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
24
|
+
<path>/test2</path>
|
25
|
+
</org.jvnet.hudson.plugins.groovypostbuild.GroovyScriptPath>
|
26
|
+
</org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder>
|
27
|
+
</publishers>
|
28
|
+
<buildWrappers/>
|
29
|
+
</project>
|
@@ -4,13 +4,13 @@ describe 'Test YAML jobs conversion to XML' do
|
|
4
4
|
context 'Loading YAML files' do
|
5
5
|
before do
|
6
6
|
@client = JenkinsApi::Client.new(
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
7
|
+
server_ip: '127.0.0.1',
|
8
|
+
server_port: 8080,
|
9
|
+
username: 'username',
|
10
|
+
password: 'password',
|
11
|
+
log_location: '/dev/null'
|
12
12
|
)
|
13
|
-
@generator = JenkinsPipelineBuilder::Generator.new(
|
13
|
+
@generator = JenkinsPipelineBuilder::Generator.new(@client)
|
14
14
|
@generator.debug = true
|
15
15
|
@generator.no_files = true
|
16
16
|
end
|
@@ -27,24 +27,27 @@ describe 'Test YAML jobs conversion to XML' do
|
|
27
27
|
doc1.should be_equivalent_to(doc2)
|
28
28
|
end
|
29
29
|
|
30
|
-
files =
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
30
|
+
files = %w(
|
31
|
+
Job-Multi-Project
|
32
|
+
Job-Build-Maven
|
33
|
+
Job-Build-Flow
|
34
|
+
Job-Gem-Build
|
35
|
+
post_build_script
|
36
|
+
properties_file
|
37
|
+
downstream
|
38
|
+
upstream
|
39
|
+
rvm05
|
40
|
+
prepare_environment
|
41
|
+
remote_job
|
42
|
+
throttle
|
43
|
+
specific_priority
|
44
|
+
periodic_build
|
45
|
+
discard_old
|
46
|
+
concurrent_build
|
47
|
+
choice_parameter
|
48
|
+
downstream_blocking
|
49
|
+
groovy_postbuild
|
50
|
+
)
|
48
51
|
|
49
52
|
files.each do |file|
|
50
53
|
it "should create expected XML from YAML '#{file}'" do
|
@@ -59,7 +62,7 @@ describe 'Test YAML jobs conversion to XML' do
|
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
62
|
-
it
|
65
|
+
it 'should create expected XML from YAML collection' do
|
63
66
|
path = File.expand_path('../fixtures/files/', __FILE__)
|
64
67
|
|
65
68
|
@generator.load_collection_from_path(path)
|
@@ -80,5 +83,7 @@ describe 'Test YAML jobs conversion to XML' do
|
|
80
83
|
compare_jobs job, file_name
|
81
84
|
end
|
82
85
|
end
|
86
|
+
|
87
|
+
it 'downloads from remote repos'
|
83
88
|
end
|
84
89
|
end
|
@@ -4,16 +4,16 @@ describe 'ModuleRegistry' do
|
|
4
4
|
|
5
5
|
it 'should return item by a specified path' do
|
6
6
|
|
7
|
-
registry = JenkinsPipelineBuilder::ModuleRegistry.new
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
7
|
+
registry = JenkinsPipelineBuilder::ModuleRegistry.new(
|
8
|
+
zz: {
|
9
|
+
aa: 'aa',
|
10
|
+
bb: 'bb',
|
11
|
+
cc: {
|
12
|
+
dd: 'dd'
|
14
13
|
}
|
15
|
-
|
14
|
+
}
|
15
|
+
)
|
16
16
|
|
17
17
|
registry.get('zz/aa').should be == 'aa'
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
@@ -3,49 +3,49 @@ require File.expand_path('../spec_helper', __FILE__)
|
|
3
3
|
describe 'Templates resolver' do
|
4
4
|
before(:each) do
|
5
5
|
@client = JenkinsApi::Client.new(
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
6
|
+
server_ip: '127.0.0.1',
|
7
|
+
server_port: 8080,
|
8
|
+
username: 'username',
|
9
|
+
password: 'password',
|
10
|
+
log_location: '/dev/null'
|
11
11
|
)
|
12
|
-
@generator = JenkinsPipelineBuilder::Generator.new(
|
12
|
+
@generator = JenkinsPipelineBuilder::Generator.new(@client)
|
13
13
|
@generator.debug = true
|
14
14
|
@generator.no_files = true
|
15
15
|
end
|
16
16
|
|
17
17
|
describe 'resolving settings bags' do
|
18
18
|
it 'gives a bag when all the variables can be resolved' do
|
19
|
-
str = %
|
19
|
+
str = %(
|
20
20
|
- project:
|
21
21
|
name: project-name
|
22
22
|
db: my_own_db_{{else}}
|
23
|
-
|
23
|
+
)
|
24
24
|
project = YAML.load(str)
|
25
25
|
@generator.load_job_collection project
|
26
26
|
|
27
|
-
|
28
|
-
settings = JenkinsPipelineBuilder::Compiler.get_settings_bag(@generator.get_item('project-name'),
|
29
|
-
settings.should == { name:
|
27
|
+
# @generator.resolve_item('project-name')
|
28
|
+
settings = JenkinsPipelineBuilder::Compiler.get_settings_bag(@generator.get_item('project-name'), db: 'blah', else: 'bum')
|
29
|
+
settings.should == { name: 'project-name', db: 'my_own_db_bum', else: 'bum' }
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'returns nil when all the variables cant be resolved' do
|
33
|
-
str = %
|
33
|
+
str = %(
|
34
34
|
- project:
|
35
35
|
name: project-name
|
36
36
|
db: my_own_db_{{else}}_{{blah}}
|
37
|
-
|
37
|
+
)
|
38
38
|
project = YAML.load(str)
|
39
39
|
@generator.load_job_collection project
|
40
40
|
|
41
|
-
|
42
|
-
settings = JenkinsPipelineBuilder::Compiler.get_settings_bag(@generator.get_item('project-name'),
|
41
|
+
# @generator.resolve_item('project-name')
|
42
|
+
settings = JenkinsPipelineBuilder::Compiler.get_settings_bag(@generator.get_item('project-name'), db: 'blah', else: 'bum')
|
43
43
|
settings.should be_nil
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'starts with the defaults section for settings bag' do
|
48
|
-
str = %
|
48
|
+
str = %(
|
49
49
|
- defaults:
|
50
50
|
name: global
|
51
51
|
description: 'Do not edit this job through the web!'
|
@@ -59,32 +59,39 @@ describe 'Templates resolver' do
|
|
59
59
|
db: my_own_db
|
60
60
|
jobs:
|
61
61
|
- 'foo-bar'
|
62
|
-
|
62
|
+
)
|
63
63
|
project = YAML.load(str)
|
64
64
|
@generator.load_job_collection project
|
65
65
|
|
66
66
|
success, project = @generator.resolve_project(@generator.get_item('project-name'))
|
67
67
|
|
68
68
|
expect(success).to be_true
|
69
|
-
expect(project).to eq(
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
69
|
+
expect(project).to eq(
|
70
|
+
name: 'project-name',
|
71
|
+
type: :project,
|
72
|
+
value: {
|
73
|
+
name: 'project-name',
|
74
|
+
db: 'my_own_db',
|
75
|
+
jobs: [{
|
76
|
+
:"foo-bar" => {},
|
77
|
+
result: {
|
78
|
+
name: 'foo-bar',
|
79
|
+
description: 'Do not edit this job through the web!',
|
80
|
+
builders: [{
|
81
|
+
shell: 'perftest' }]
|
82
|
+
}
|
83
|
+
}]
|
84
|
+
},
|
85
|
+
settings: {
|
86
|
+
name: 'project-name',
|
87
|
+
description: 'Do not edit this job through the web!',
|
88
|
+
db: 'my_own_db'
|
89
|
+
}
|
90
|
+
)
|
84
91
|
end
|
85
92
|
|
86
93
|
it 'should build project collection from jobs templates' do
|
87
|
-
str = %
|
94
|
+
str = %(
|
88
95
|
- job-template:
|
89
96
|
name: '{{name}}-unit-tests'
|
90
97
|
builders:
|
@@ -109,34 +116,41 @@ describe 'Templates resolver' do
|
|
109
116
|
mail-to: developer@nowhere.net
|
110
117
|
- '{{name}}-perf-tests':
|
111
118
|
mail-to: projmanager@nowhere.net
|
112
|
-
|
119
|
+
)
|
113
120
|
|
114
121
|
project = YAML.load(str)
|
115
122
|
@generator.load_job_collection project
|
116
123
|
|
117
124
|
success, project = @generator.resolve_project(@generator.get_item('project-name'))
|
118
125
|
expect(success).to be_true
|
119
|
-
expect(project).to eq(
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
126
|
+
expect(project).to eq(
|
127
|
+
name: 'project-name',
|
128
|
+
type: :project,
|
129
|
+
value: {
|
130
|
+
name: 'project-name',
|
131
|
+
db: 'my_own_db',
|
132
|
+
jobs: [{
|
133
|
+
:"{{name}}-unit-tests" => { :"mail-to" => 'developer@nowhere.net' },
|
134
|
+
result: {
|
135
|
+
name: 'project-name-unit-tests',
|
136
|
+
builders: [{ shell: 'unittest' }],
|
137
|
+
publishers: [{ email: { recipients: 'developer@nowhere.net' } }]
|
138
|
+
}
|
139
|
+
}, {
|
140
|
+
:"{{name}}-perf-tests" => { :"mail-to" => 'projmanager@nowhere.net' },
|
141
|
+
result: {
|
142
|
+
name: 'project-name-perf-tests',
|
143
|
+
builders: [{ shell: 'perftest' }],
|
144
|
+
publishers: [{ email: { recipients: 'projmanager@nowhere.net' } }]
|
145
|
+
}
|
146
|
+
}]
|
147
|
+
},
|
148
|
+
settings: { name: 'project-name', db: 'my_own_db' }
|
149
|
+
)
|
136
150
|
end
|
137
151
|
|
138
152
|
it 'should build project collection from jobs and jobs templates' do
|
139
|
-
str = %
|
153
|
+
str = %(
|
140
154
|
- job-template:
|
141
155
|
name: '{{name}}-unit-tests'
|
142
156
|
builders:
|
@@ -157,64 +171,69 @@ describe 'Templates resolver' do
|
|
157
171
|
- 'foo-bar'
|
158
172
|
- '{{name}}-unit-tests':
|
159
173
|
mail-to: projmanager@nowhere.net
|
160
|
-
|
174
|
+
)
|
161
175
|
|
162
176
|
project = YAML.load(str)
|
163
177
|
@generator.load_job_collection project
|
164
178
|
|
165
179
|
success, project = @generator.resolve_project(@generator.get_item('project-name'))
|
166
|
-
|
180
|
+
expect(success).to be_true
|
167
181
|
expect(project).to eq(
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
182
|
+
name: 'project-name',
|
183
|
+
type: :project,
|
184
|
+
value: {
|
185
|
+
name: 'project-name',
|
186
|
+
db: 'my_own_db',
|
187
|
+
jobs: [{
|
188
|
+
:"foo-bar" => {},
|
189
|
+
result: {
|
190
|
+
name: 'foo-bar',
|
191
|
+
builders: [{ shell: 'perftest' }]
|
192
|
+
}
|
193
|
+
}, {
|
194
|
+
:"{{name}}-unit-tests" => { :"mail-to" => 'projmanager@nowhere.net' },
|
195
|
+
result: {
|
196
|
+
name: 'project-name-unit-tests',
|
197
|
+
builders: [{ shell: 'unittest' }],
|
198
|
+
publishers: [{ email: { recipients: 'projmanager@nowhere.net' } }]
|
199
|
+
}
|
200
|
+
}]
|
201
|
+
},
|
202
|
+
settings: { name: 'project-name', db: 'my_own_db' }
|
203
|
+
)
|
184
204
|
end
|
185
205
|
|
186
|
-
|
187
206
|
describe 'compilation of templates' do
|
188
207
|
it 'compiles String' do
|
189
|
-
success, string = JenkinsPipelineBuilder::Compiler.compile('blah',
|
208
|
+
success, string = JenkinsPipelineBuilder::Compiler.compile('blah', item1: 'data1')
|
190
209
|
expect(success).to be_true
|
191
210
|
expect(string).to eq 'blah'
|
192
211
|
end
|
193
212
|
|
194
213
|
it 'compiles simple Hash' do
|
195
|
-
success, hash = JenkinsPipelineBuilder::Compiler.compile({ name: 'item-{{item1}}', value: 'item1-data'},
|
214
|
+
success, hash = JenkinsPipelineBuilder::Compiler.compile({ name: 'item-{{item1}}', value: 'item1-data' }, item1: 'data1')
|
196
215
|
expect(success).to be_true
|
197
|
-
expect(hash).to eq(
|
216
|
+
expect(hash).to eq(name: 'item-data1', value: 'item1-data')
|
198
217
|
end
|
199
218
|
|
200
219
|
it 'compiles nested Hash' do
|
201
|
-
success, hash = JenkinsPipelineBuilder::Compiler.compile({ name: 'item-{{item1}}', value: { house: 'house-{{item1}}'}},
|
220
|
+
success, hash = JenkinsPipelineBuilder::Compiler.compile({ name: 'item-{{item1}}', value: { house: 'house-{{item1}}' } }, item1: 'data1')
|
202
221
|
expect(success).to be_true
|
203
|
-
expect(hash).to eq(
|
222
|
+
expect(hash).to eq(name: 'item-data1', value: { house: 'house-data1' })
|
204
223
|
end
|
205
224
|
|
206
225
|
it 'compiles complex Hash' do
|
207
|
-
template = {:
|
208
|
-
|
209
|
-
|
210
|
-
settings = {:
|
226
|
+
template = { name: '{{name}}-unit-tests',
|
227
|
+
builders: [{ shell: 'unittest' }],
|
228
|
+
publishers: [{ email: { recipients: '{{mail-to}}' } }] }
|
229
|
+
settings = { name: 'project-name', db: 'my_own_db', :'mail-to' => 'developer@nowhere.net' }
|
211
230
|
|
212
231
|
success, hash = JenkinsPipelineBuilder::Compiler.compile(template, settings)
|
213
232
|
expect(success).to be_true
|
214
233
|
expect(hash).to eq(
|
215
|
-
|
216
|
-
|
217
|
-
|
234
|
+
name: 'project-name-unit-tests',
|
235
|
+
builders: [{ shell: 'unittest' }],
|
236
|
+
publishers: [{ email: { recipients: 'developer@nowhere.net' } }])
|
218
237
|
end
|
219
238
|
end
|
220
239
|
|
@@ -225,19 +244,19 @@ describe 'Templates resolver' do
|
|
225
244
|
|
226
245
|
@generator.load_job_collection project
|
227
246
|
|
228
|
-
success, job = @generator.resolve_job_by_name('{{name}}-unit-tests',
|
247
|
+
success, job = @generator.resolve_job_by_name('{{name}}-unit-tests', name: 'project-name', db: 'my_own_db', :'mail-to' => 'developer@nowhere.net')
|
229
248
|
expect(success).to be_true
|
230
249
|
expect(job).to eq(
|
231
|
-
|
232
|
-
|
233
|
-
|
250
|
+
name: 'project-name-unit-tests',
|
251
|
+
builders: [{ shell: 'unittest' }],
|
252
|
+
publishers: [{ email: { recipients: 'developer@nowhere.net' } }])
|
234
253
|
end
|
235
254
|
|
236
255
|
it 'should load from folder' do
|
237
256
|
path = File.expand_path('../fixtures/templates/', __FILE__)
|
238
257
|
@generator.load_collection_from_path(path)
|
239
258
|
|
240
|
-
@generator.job_collection.count.should
|
241
|
-
@generator.projects.count
|
259
|
+
@generator.job_collection.count.should eq 4
|
260
|
+
@generator.projects.count.should eq 1
|
242
261
|
end
|
243
262
|
end
|