jenkins_pipeline_builder 0.1.2 → 0.1.3

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-gemset +1 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +4 -0
  5. data/Rakefile +68 -0
  6. data/bin/generate +28 -0
  7. data/config/login.yml +24 -0
  8. data/jenkins_pipeline_builder.gemspec +42 -0
  9. data/lib/jenksin_pipeline_builder.rb +39 -0
  10. data/lib/jenksin_pipeline_builder/builders.rb +72 -0
  11. data/lib/jenksin_pipeline_builder/cli/base.rb +69 -0
  12. data/lib/jenksin_pipeline_builder/cli/helper.rb +68 -0
  13. data/lib/jenksin_pipeline_builder/cli/pipeline.rb +40 -0
  14. data/lib/jenksin_pipeline_builder/cli/view.rb +40 -0
  15. data/lib/jenksin_pipeline_builder/compiler.rb +81 -0
  16. data/lib/jenksin_pipeline_builder/generator.rb +346 -0
  17. data/lib/jenksin_pipeline_builder/job_builder.rb +82 -0
  18. data/lib/jenksin_pipeline_builder/module_registry.rb +82 -0
  19. data/lib/jenksin_pipeline_builder/publishers.rb +113 -0
  20. data/lib/jenksin_pipeline_builder/triggers.rb +38 -0
  21. data/lib/jenksin_pipeline_builder/utils.rb +46 -0
  22. data/lib/jenksin_pipeline_builder/version.rb +25 -0
  23. data/lib/jenksin_pipeline_builder/view.rb +259 -0
  24. data/lib/jenksin_pipeline_builder/wrappers.rb +91 -0
  25. data/lib/jenksin_pipeline_builder/xml_helper.rb +40 -0
  26. data/spec/func_tests/spec_helper.rb +18 -0
  27. data/spec/func_tests/view_spec.rb +93 -0
  28. data/spec/unit_tests/compiler_spec.rb +19 -0
  29. data/spec/unit_tests/fixtures/files/Job-Build-Flow.xml +57 -0
  30. data/spec/unit_tests/fixtures/files/Job-Build-Flow.yaml +22 -0
  31. data/spec/unit_tests/fixtures/files/Job-Build-Maven.xml +90 -0
  32. data/spec/unit_tests/fixtures/files/Job-Build-Maven.yaml +26 -0
  33. data/spec/unit_tests/fixtures/files/Job-DSL.yaml +14 -0
  34. data/spec/unit_tests/fixtures/files/Job-DSL1.xml +27 -0
  35. data/spec/unit_tests/fixtures/files/Job-DSL2.xml +25 -0
  36. data/spec/unit_tests/fixtures/files/Job-Gem-Build.xml +142 -0
  37. data/spec/unit_tests/fixtures/files/Job-Gem-Build.yaml +41 -0
  38. data/spec/unit_tests/fixtures/files/Job-Generate-From-Template.xml +32 -0
  39. data/spec/unit_tests/fixtures/files/Job-Generate-From-Template.yaml +8 -0
  40. data/spec/unit_tests/fixtures/files/Job-Multi-Project.xml +117 -0
  41. data/spec/unit_tests/fixtures/files/Job-Multi-Project.yaml +36 -0
  42. data/spec/unit_tests/fixtures/files/project.yaml +15 -0
  43. data/spec/unit_tests/generator_spec.rb +67 -0
  44. data/spec/unit_tests/module_registry_spec.rb +19 -0
  45. data/spec/unit_tests/resolve_dependencies_spec.rb +230 -0
  46. data/spec/unit_tests/spec_helper.rb +29 -0
  47. metadata +75 -6
@@ -0,0 +1,91 @@
1
+ #
2
+ # Copyright (c) 2014 Igor Moochnick
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 Wrappers
25
+ def self.ansicolor(wrapper, xml)
26
+ xml.send('hudson.plugins.ansicolor.AnsiColorBuildWrapper') {
27
+ xml.colorMapName 'xterm'
28
+ }
29
+ end
30
+
31
+ def self.console_timestamp(wrapper, xml)
32
+ xml.send('hudson.plugins.timestamper.TimestamperBuildWrapper')
33
+ end
34
+
35
+ def self.run_with_rvm(wrapper, xml)
36
+ xml.send('ruby-proxy-object') {
37
+ xml.send('ruby-object', 'ruby-class' => 'Jenkins::Plugin::Proxies::BuildWrapper', 'pluginid' => 'rvm') {
38
+ xml.object('ruby-class' => 'RvmWrapper', 'pluginid' => 'rvm') {
39
+ xml.impl('pluginid' => "rvm", 'ruby-class' => 'String') { xml.text wrapper }
40
+ }
41
+ xml.pluginid(:pluginid => 'rvm', 'ruby-class' => 'String') { xml.text 'rvm' }
42
+ }
43
+ }
44
+ end
45
+
46
+ def self.inject_passwords(passwords, xml)
47
+ xml.EnvInjectPasswordWrapper {
48
+ xml.injectGlobalPasswords false
49
+ xml.passwordEntries {
50
+ passwords.each do |password|
51
+ xml.EnvInjectPasswordEntry {
52
+ xml.name password[:name]
53
+ xml.value password[:value]
54
+ }
55
+ end
56
+ }
57
+ }
58
+ end
59
+
60
+ def self.inject_env_vars(wrapper, xml)
61
+ xml.EnvInjectBuildWrapper {
62
+ xml.info {
63
+ xml.propertiesContent wrapper
64
+ xml.loadFilesFromMaster false
65
+ }
66
+ }
67
+ end
68
+
69
+ def self.publish_to_artifactory(wrapper, xml)
70
+ xml.send('org.jfrog.hudson.generic.ArtifactoryGenericConfigurator') {
71
+ xml.details {
72
+ xml.artifactoryUrl wrapper[:url]
73
+ xml.artifactoryName wrapper[:'artifactory-name']
74
+ xml.repositoryKey wrapper[:'target-repo']
75
+ xml.snapshotsRepositoryKey wrapper[:'target-repo']
76
+ }
77
+ xml.deployPattern wrapper[:publish]
78
+ xml.resolvePattern
79
+ xml.matrixParams
80
+ xml.deployBuildInfo wrapper[:'publish-build-info']
81
+ xml.includeEnvVars false
82
+ xml.envVarsPatterns {
83
+ xml.includePatterns
84
+ xml.excludePatterns '*password*,*secret*'
85
+ }
86
+ xml.discardOldBuilds false
87
+ xml.discardBuildArtifacts true
88
+ }
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ # Copyright (c) 2014 Igor Moochnick
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 XmlHelper
25
+ def self.update_node_text(n_xml, path, value)
26
+ n_node = n_xml.xpath(path).first
27
+ if n_node.nil?
28
+ left, right = path.match(/^(.*)\/([^\/]*)$/).captures
29
+ parent_node = n_xml.xpath(left).first
30
+ Nokogiri::XML::Builder.with(parent_node) do |xml|
31
+ xml.send(right) {
32
+ xml.text value
33
+ }
34
+ end
35
+ else
36
+ n_node.content = value
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ require 'logger'
2
+ require 'rspec'
3
+
4
+ require 'simplecov'
5
+ require 'simplecov-rcov'
6
+
7
+ SimpleCov.start if ENV["COVERAGE"]
8
+
9
+ require File.expand_path('../../../lib/jenksin_pipeline_builder', __FILE__)
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run_excluding :broken => true
15
+
16
+ config.before(:each) do
17
+ end
18
+ end
@@ -0,0 +1,93 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe JenkinsPipelineBuilder::View do
4
+ context "With properly initialized client" do
5
+ before(:all) do
6
+ @creds_file = '~/.jenkins_api_client/login.yml'
7
+ @valid_post_responses = [200, 201, 302]
8
+ begin
9
+ @client = JenkinsApi::Client.new(
10
+ YAML.load_file(File.expand_path(@creds_file, __FILE__))
11
+ )
12
+ @client.logger.level = Logger::DEBUG
13
+ @generator = JenkinsPipelineBuilder::Generator.new(nil, @client)
14
+ @generator.no_files = true
15
+ rescue Exception => e
16
+ puts 'WARNING: Credentials are not set properly.'
17
+ puts e.message
18
+ end
19
+ end
20
+
21
+ describe 'InstanceMethods' do
22
+ describe '#create' do
23
+ def create_and_validate(params)
24
+ name = params[:name]
25
+ @valid_post_responses.should include(
26
+ @generator.view.create(params).to_i
27
+ )
28
+ @generator.view.list_children(params[:parent_view], name).include?(name).should be_true
29
+ end
30
+
31
+ def destroy_and_validate(params)
32
+ name = params[:name]
33
+ @valid_post_responses.should include(
34
+ @generator.view.delete(name, params[:parent_view]).to_i
35
+ )
36
+ @generator.view.list_children(params[:parent_view], name).include?(name).should be_false
37
+ end
38
+
39
+ def test_and_validate(params)
40
+ create_and_validate(params)
41
+ destroy_and_validate(params)
42
+ end
43
+
44
+ it 'accepts the name of the view and creates the view' do
45
+ params = {
46
+ :name => 'test_list_view'
47
+ }
48
+
49
+ test_and_validate(params)
50
+ end
51
+
52
+ it 'creates a Nested view with a child' do
53
+ params_parent = {
54
+ name: 'test_nested_view',
55
+ type: 'nestedView'
56
+ }
57
+
58
+ create_and_validate(params_parent)
59
+
60
+ params_child = {
61
+ name: 'test_list_view',
62
+ parent_view: params_parent[:name]
63
+ }
64
+
65
+ test_and_validate(params_child)
66
+
67
+ destroy_and_validate(params_parent)
68
+ end
69
+
70
+ it 'creates a categorized view with columns' do
71
+ params = {
72
+ name: 'test_category_view',
73
+ type: 'categorizedView',
74
+ description: 'Blah blah',
75
+ regex: 'Job-.*',
76
+ groupingRules: [{
77
+ groupRegex: 'Step-1.*',
78
+ namingRule: '1. Commit'
79
+ },{
80
+ groupRegex: 'Step-2.*',
81
+ namingRule: '2. Acceptance'
82
+ },{
83
+ groupRegex: 'Step-3.*',
84
+ namingRule: '3. Release'
85
+ }]
86
+ }
87
+
88
+ test_and_validate(params)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe 'Compiler' do
4
+ it 'transforms hash into hash' do
5
+ hash = {
6
+ a: 'A sentence',
7
+ b: 'B sentence',
8
+ hash: {
9
+ c: 5,
10
+ d: true
11
+ },
12
+ z: false
13
+ }
14
+
15
+ result = JenkinsPipelineBuilder::Compiler.compile(hash)
16
+
17
+ result.should == hash
18
+ end
19
+ end
@@ -0,0 +1,57 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <com.cloudbees.plugins.flow.BuildFlow>
3
+ <actions/>
4
+ <description/>
5
+ <keepDependencies>false</keepDependencies>
6
+ <properties>
7
+ <jenkins.plugins.hipchat.HipChatNotifier_-HipChatJobProperty>
8
+ <room>HipChat Room Name</room>
9
+ <startNotification>true</startNotification>
10
+ </jenkins.plugins.hipchat.HipChatNotifier_-HipChatJobProperty>
11
+ <hudson.model.ParametersDefinitionProperty>
12
+ <parameterDefinitions>
13
+ <hudson.model.StringParameterDefinition>
14
+ <name>param1</name>
15
+ <description/>
16
+ <defaultValue/>
17
+ </hudson.model.StringParameterDefinition>
18
+ </parameterDefinitions>
19
+ </hudson.model.ParametersDefinitionProperty>
20
+ </properties>
21
+ <scm class="hudson.scm.NullSCM"/>
22
+ <canRoam>true</canRoam>
23
+ <disabled>false</disabled>
24
+ <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
25
+ <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
26
+ <triggers class="vector"/>
27
+ <concurrentBuild>false</concurrentBuild>
28
+ <builders/>
29
+ <publishers>
30
+ <hudson.plugins.parameterizedtrigger.BuildTrigger>
31
+ <configs>
32
+ <hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
33
+ <configs>
34
+ <hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
35
+ <properties/>
36
+ </hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
37
+ </configs>
38
+ <projects>project_name</projects>
39
+ <condition>SUCCESS</condition>
40
+ <triggerWithNoParameters>false</triggerWithNoParameters>
41
+ </hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
42
+ </configs>
43
+ </hudson.plugins.parameterizedtrigger.BuildTrigger>
44
+ <jenkins.plugins.hipchat.HipChatNotifier>
45
+ <jenkinsUrl>https://jenkins_url/</jenkinsUrl>
46
+ <authToken>auth_token</authToken>
47
+ <room>room name</room>
48
+ </jenkins.plugins.hipchat.HipChatNotifier>
49
+ </publishers>
50
+ <buildWrappers/>
51
+ <dsl>guard {
52
+ build("job_name1", param1: params["param1"]);
53
+ } rescue {
54
+ build("job_name2", param1: build21.environment.get("some_var"))
55
+ }
56
+ </dsl>
57
+ </com.cloudbees.plugins.flow.BuildFlow>
@@ -0,0 +1,22 @@
1
+ ---
2
+ - job:
3
+ name: Job-Build-Flow
4
+ job_type: build_flow
5
+ hipchat:
6
+ room: 'HipChat Room Name'
7
+ start-notify: true
8
+ parameters:
9
+ - name: param1
10
+ publishers:
11
+ - downstream:
12
+ project: project_name
13
+ - hipchat:
14
+ jenkinsUrl: 'https://jenkins_url/'
15
+ authToken: 'auth_token'
16
+ room: 'room name'
17
+ build_flow: |
18
+ guard {
19
+ build("job_name1", param1: params["param1"]);
20
+ } rescue {
21
+ build("job_name2", param1: build21.environment.get("some_var"))
22
+ }
@@ -0,0 +1,90 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project>
3
+ <actions/>
4
+ <description/>
5
+ <keepDependencies>false</keepDependencies>
6
+ <properties/>
7
+ <scm class="hudson.plugins.git.GitSCM">
8
+ <configVersion>2</configVersion>
9
+ <userRemoteConfigs>
10
+ <hudson.plugins.git.UserRemoteConfig>
11
+ <name/>
12
+ <refspec/>
13
+ <url>git@github.com:devops/repo.git</url>
14
+ </hudson.plugins.git.UserRemoteConfig>
15
+ </userRemoteConfigs>
16
+ <branches>
17
+ <hudson.plugins.git.BranchSpec>
18
+ <name>release</name>
19
+ </hudson.plugins.git.BranchSpec>
20
+ </branches>
21
+ <localBranch>release</localBranch>
22
+ <disableSubmodules>false</disableSubmodules>
23
+ <recursiveSubmodules>false</recursiveSubmodules>
24
+ <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
25
+ <authorOrCommitter>false</authorOrCommitter>
26
+ <clean>false</clean>
27
+ <wipeOutWorkspace>true</wipeOutWorkspace>
28
+ <pruneBranches>false</pruneBranches>
29
+ <remotePoll>false</remotePoll>
30
+ <ignoreNotifyCommit>false</ignoreNotifyCommit>
31
+ <useShallowClone>false</useShallowClone>
32
+ <buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
33
+ <gitTool>Default</gitTool>
34
+ <submoduleCfg class="list"/>
35
+ <relativeTargetDir/>
36
+ <reference/>
37
+ <excludedRegions/>
38
+ <excludedUsers>user</excludedUsers>
39
+ <gitConfigName/>
40
+ <gitConfigEmail/>
41
+ <skipTag>false</skipTag>
42
+ <includedRegions/>
43
+ <scmName/>
44
+ </scm>
45
+ <canRoam>true</canRoam>
46
+ <disabled>false</disabled>
47
+ <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
48
+ <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
49
+ <triggers class="vector"/>
50
+ <concurrentBuild>false</concurrentBuild>
51
+ <builders>
52
+ <hudson.tasks.Shell>
53
+ <command>echo 'Doing some work'
54
+ run command1
55
+ </command>
56
+ </hudson.tasks.Shell>
57
+ <org.jfrog.hudson.maven3.Maven3Builder>
58
+ <mavenName>tools-maven-3.0.3</mavenName>
59
+ <rootPom/>
60
+ <goals>-B clean</goals>
61
+ <mavenOpts/>
62
+ </org.jfrog.hudson.maven3.Maven3Builder>
63
+ </builders>
64
+ <publishers>
65
+ <hudson.plugins.descriptionsetter.DescriptionSetterPublisher>
66
+ <regexp>See the QE build details at (.*)</regexp>
67
+ <regexpForFailed>See the QE build details at (.*)</regexpForFailed>
68
+ <description>QE Build Details: &lt;a href="\1"&gt;\1&lt;/a&gt;</description>
69
+ <descriptionForFailed>QE Build Details: &lt;a href="\1"&gt;\1&lt;/a&gt;</descriptionForFailed>
70
+ <setForMatrix>false</setForMatrix>
71
+ </hudson.plugins.descriptionsetter.DescriptionSetterPublisher>
72
+ <hudson.plugins.parameterizedtrigger.BuildTrigger>
73
+ <configs>
74
+ <hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
75
+ <configs>
76
+ <hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
77
+ <properties>VM_NAME=${VM_NAME}</properties>
78
+ </hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
79
+ </configs>
80
+ <projects>project_name</projects>
81
+ <condition>SUCCESS</condition>
82
+ <triggerWithNoParameters>false</triggerWithNoParameters>
83
+ </hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
84
+ </configs>
85
+ </hudson.plugins.parameterizedtrigger.BuildTrigger>
86
+ </publishers>
87
+ <buildWrappers>
88
+ <hudson.plugins.timestamper.TimestamperBuildWrapper/>
89
+ </buildWrappers>
90
+ </project>
@@ -0,0 +1,26 @@
1
+ ---
2
+ - job:
3
+ name: Job-Build-Maven
4
+ scm_provider: git
5
+ scm_url: git@github.com:devops/repo.git
6
+ scm_branch: release
7
+ scm_params:
8
+ local_branch: release
9
+ wipe_workspace: true
10
+ excuded_users: user
11
+ builders:
12
+ - shell_command: |
13
+ echo 'Doing some work'
14
+ run command1
15
+ - maven3:
16
+ goals: -B clean
17
+ publishers:
18
+ - description_setter:
19
+ regexp: See the QE build details at (.*)
20
+ description: 'QE Build Details: <a href="\1">\1</a>'
21
+ - downstream:
22
+ project: project_name
23
+ data:
24
+ - params: VM_NAME=${VM_NAME}
25
+ wrappers:
26
+ - timestamp: true