rubyjobbuilderdsl 0.0.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.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +6 -0
  3. data/Gemfile.lock +33 -0
  4. data/LICENSE +19 -0
  5. data/Rakefile +12 -0
  6. data/docs/common.md +313 -0
  7. data/docs/flow.md +18 -0
  8. data/docs/freestyle.md +100 -0
  9. data/docs/gerrit.md +70 -0
  10. data/docs/git.md +88 -0
  11. data/docs/index.md +11 -0
  12. data/docs/multi.md +27 -0
  13. data/docs/overview.md +74 -0
  14. data/docs/postbuild.md +266 -0
  15. data/docs/view.md +13 -0
  16. data/lib/rubyjobbuilderdsl/builder.rb +69 -0
  17. data/lib/rubyjobbuilderdsl/buildstep/ant.rb +29 -0
  18. data/lib/rubyjobbuilderdsl/buildstep/copyartifact.rb +23 -0
  19. data/lib/rubyjobbuilderdsl/buildstep/inject_env.rb +18 -0
  20. data/lib/rubyjobbuilderdsl/buildstep/phase.rb +19 -0
  21. data/lib/rubyjobbuilderdsl/buildstep/phase_job.rb +26 -0
  22. data/lib/rubyjobbuilderdsl/buildstep/shell.rb +24 -0
  23. data/lib/rubyjobbuilderdsl/common/artifactory.rb +33 -0
  24. data/lib/rubyjobbuilderdsl/common/blocking_job.rb +11 -0
  25. data/lib/rubyjobbuilderdsl/common/build_timeout.rb +23 -0
  26. data/lib/rubyjobbuilderdsl/common/gerrit.rb +53 -0
  27. data/lib/rubyjobbuilderdsl/common/git.rb +76 -0
  28. data/lib/rubyjobbuilderdsl/common/logrotate.rb +24 -0
  29. data/lib/rubyjobbuilderdsl/common/parameter.rb +22 -0
  30. data/lib/rubyjobbuilderdsl/common/password.rb +12 -0
  31. data/lib/rubyjobbuilderdsl/common/pollscm.rb +10 -0
  32. data/lib/rubyjobbuilderdsl/common/scms.rb +18 -0
  33. data/lib/rubyjobbuilderdsl/common/throttle.rb +24 -0
  34. data/lib/rubyjobbuilderdsl/common/timed.rb +10 -0
  35. data/lib/rubyjobbuilderdsl/common/timestamps.rb +6 -0
  36. data/lib/rubyjobbuilderdsl/common.rb +140 -0
  37. data/lib/rubyjobbuilderdsl/deployer.rb +95 -0
  38. data/lib/rubyjobbuilderdsl/flow.rb +14 -0
  39. data/lib/rubyjobbuilderdsl/freestyle.rb +57 -0
  40. data/lib/rubyjobbuilderdsl/jenkins_client.rb +203 -0
  41. data/lib/rubyjobbuilderdsl/multijob.rb +24 -0
  42. data/lib/rubyjobbuilderdsl/postbuild/archive.rb +23 -0
  43. data/lib/rubyjobbuilderdsl/postbuild/chucknorris_publisher.rb +6 -0
  44. data/lib/rubyjobbuilderdsl/postbuild/claim_publisher.rb +6 -0
  45. data/lib/rubyjobbuilderdsl/postbuild/cloverphp_publisher.rb +36 -0
  46. data/lib/rubyjobbuilderdsl/postbuild/email_publisher.rb +23 -0
  47. data/lib/rubyjobbuilderdsl/postbuild/game_publisher.rb +6 -0
  48. data/lib/rubyjobbuilderdsl/postbuild/groovy.rb +10 -0
  49. data/lib/rubyjobbuilderdsl/postbuild/html_publisher.rb +27 -0
  50. data/lib/rubyjobbuilderdsl/postbuild/javadoc_publisher.rb +19 -0
  51. data/lib/rubyjobbuilderdsl/postbuild/logparser.rb +21 -0
  52. data/lib/rubyjobbuilderdsl/postbuild/nunit_publisher.rb +21 -0
  53. data/lib/rubyjobbuilderdsl/postbuild/pmd_publisher.rb +19 -0
  54. data/lib/rubyjobbuilderdsl/postbuild/script.rb +14 -0
  55. data/lib/rubyjobbuilderdsl/postbuild/tap_publisher.rb +44 -0
  56. data/lib/rubyjobbuilderdsl/postbuild/trigger.rb +38 -0
  57. data/lib/rubyjobbuilderdsl/postbuild/xunit_publisher.rb +35 -0
  58. data/lib/rubyjobbuilderdsl/postbuild.rb +146 -0
  59. data/lib/rubyjobbuilderdsl/view.rb +14 -0
  60. data/lib/rubyjobbuilderdsl/xml_generator.rb +839 -0
  61. data/lib/rubyjobbuilderdsl.rb +2 -0
  62. data/rubyjobbuilderdsl.gemspec +13 -0
  63. data/rubyjobbuilderdsl.sublime-project +14 -0
  64. data/run_tests.sh +7 -0
  65. data/sample/hello_mars.rb +27 -0
  66. data/sample/local.ini +4 -0
  67. data/test/test_ant.rb +38 -0
  68. data/test/test_archive.rb +24 -0
  69. data/test/test_artifactory.rb +26 -0
  70. data/test/test_blocking_job.rb +18 -0
  71. data/test/test_chucknorris_publisher.rb +17 -0
  72. data/test/test_claim_publisher.rb +17 -0
  73. data/test/test_cloverphp.rb +33 -0
  74. data/test/test_concurrent.rb +44 -0
  75. data/test/test_copyartifact.rb +45 -0
  76. data/test/test_default_setting.rb +29 -0
  77. data/test/test_email_publisher.rb +44 -0
  78. data/test/test_flow.rb +19 -0
  79. data/test/test_freestyle.rb +52 -0
  80. data/test/test_game_publisher.rb +17 -0
  81. data/test/test_gerrit.rb +117 -0
  82. data/test/test_git.rb +80 -0
  83. data/test/test_html_publisher.rb +57 -0
  84. data/test/test_inject.rb +23 -0
  85. data/test/test_javadoc.rb +22 -0
  86. data/test/test_logparser.rb +24 -0
  87. data/test/test_logrotate.rb +22 -0
  88. data/test/test_multijob.rb +50 -0
  89. data/test/test_nunit_publisher.rb +20 -0
  90. data/test/test_parameter.rb +44 -0
  91. data/test/test_password.rb +17 -0
  92. data/test/test_pmd.rb +22 -0
  93. data/test/test_pollscm.rb +15 -0
  94. data/test/test_postbuild_groovy.rb +21 -0
  95. data/test/test_postbuild_script.rb +24 -0
  96. data/test/test_postbuild_trigger.rb +170 -0
  97. data/test/test_scms.rb +31 -0
  98. data/test/test_tap_publisher.rb +25 -0
  99. data/test/test_timed.rb +15 -0
  100. data/test/test_timeout.rb +20 -0
  101. data/test/test_timestamps.rb +14 -0
  102. data/test/test_xml_generator.rb +28 -0
  103. data/test/test_xunit_publisher.rb +22 -0
  104. metadata +173 -0
@@ -0,0 +1,76 @@
1
+ module JenkinsJob
2
+ module Common
3
+ class Git < BasicObject
4
+ attr_reader :url_, :basedir_, :reference_repo_, :branches_, :refspec_,
5
+ :choosing_strategy_, :git_config_name_, :git_config_email_,
6
+ :fastpoll_, :files_, :wipe_workspace_, :clean_, :jgit_, :credentials_
7
+
8
+ def initialize
9
+ @fastpoll_ = true
10
+ @branches_ = ['*/master']
11
+ @jgit_ = false
12
+ end
13
+
14
+ def url(value)
15
+ @url_ = value
16
+ end
17
+
18
+ def basedir(value)
19
+ @basedir_ = value
20
+ end
21
+
22
+ def reference_repo(value)
23
+ @reference_repo_ = value
24
+ end
25
+
26
+ # @deprecated Please use {#branch}
27
+ def branches(*value)
28
+ branch(*value)
29
+ end
30
+
31
+ def branch(*value)
32
+ @branches_ = value
33
+ end
34
+
35
+ def refspec(value)
36
+ @refspec_ = value
37
+ end
38
+
39
+ def choosing_strategy(value)
40
+ @choosing_strategy_ = value
41
+ end
42
+
43
+ def git_config_name(value)
44
+ @git_config_name_ = value
45
+ end
46
+
47
+ def git_config_email(value)
48
+ @git_config_email_ = value
49
+ end
50
+
51
+ def fastpoll(value = true)
52
+ @fastpoll_ = value
53
+ end
54
+
55
+ def file(*value)
56
+ @files_ = value
57
+ end
58
+
59
+ def clean(value = false)
60
+ @clean_ = value
61
+ end
62
+
63
+ def wipe_workspace(value = true)
64
+ @wipe_workspace_ = value
65
+ end
66
+
67
+ def jgit
68
+ @jgit_ = true
69
+ end
70
+
71
+ def credentials(value)
72
+ @credentials_ = value
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,24 @@
1
+ module JenkinsJob
2
+ module Common
3
+ class LogRotate < BasicObject
4
+ attr_reader :days_to_keep_, :num_to_keep_,
5
+ :artifact_days_to_keep_, :artifact_num_to_keep_
6
+
7
+ def days_to_keep(value)
8
+ @days_to_keep_ = value
9
+ end
10
+
11
+ def num_to_keep(value)
12
+ @num_to_keep_ = value
13
+ end
14
+
15
+ def artifact_days_to_keep(value)
16
+ @artifact_days_to_keep_ = value
17
+ end
18
+
19
+ def artifact_num_to_keep(value)
20
+ @artifact_num_to_keep_ = value
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ module JenkinsJob
2
+ module Common
3
+ class Parameter < BasicObject
4
+ attr_reader :name, :default_, :description_
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ end
9
+
10
+ def default(value)
11
+ @default_ = value
12
+ end
13
+
14
+ def description(value)
15
+ @description_ = value
16
+ end
17
+ end
18
+
19
+ class PasswordParameter < Parameter
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module JenkinsJob
2
+ module Common
3
+ class Password < BasicObject
4
+ attr_reader :name_, :password_
5
+
6
+ def initialize(name, password)
7
+ @name_ = name
8
+ @password_ = password
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module JenkinsJob
2
+ module Common
3
+ class PollSCM < BasicObject
4
+ attr_reader :value_
5
+ def initialize(value)
6
+ @value_ = value
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ module JenkinsJob
2
+ module Common
3
+ class Scms < BasicObject
4
+ attr_reader :scms_
5
+
6
+ def initialize
7
+ @scms_ = []
8
+ end
9
+
10
+ def git(&block)
11
+ git = Git.new
12
+ git.instance_eval(&block)
13
+
14
+ @scms_ << git
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ module JenkinsJob
2
+ module Common
3
+ class Throttle < BasicObject
4
+ attr_reader :categories_, :max_per_node_, :max_total_
5
+
6
+ def initialize
7
+ @max_per_node_ = 1
8
+ @max_total_ = 0
9
+ end
10
+
11
+ def max_per_node(value)
12
+ @max_per_node_ = value
13
+ end
14
+
15
+ def max_total(value)
16
+ @max_total_ = value
17
+ end
18
+
19
+ def category(*value)
20
+ @categories_ = value
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ module JenkinsJob
2
+ module Common
3
+ class Timed < BasicObject
4
+ attr_reader :value_
5
+ def initialize(value)
6
+ @value_ = value
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ module JenkinsJob
2
+ module Common
3
+ class Timestamps < BasicObject
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,140 @@
1
+ require_relative 'common/parameter'
2
+ require_relative 'common/git'
3
+ require_relative 'common/gerrit'
4
+ require_relative 'common/logrotate'
5
+ require_relative 'common/scms'
6
+ require_relative 'common/throttle'
7
+ require_relative 'common/build_timeout'
8
+ require_relative 'common/artifactory'
9
+ require_relative 'common/pollscm'
10
+ require_relative 'common/timed'
11
+ require_relative 'common/password'
12
+ require_relative 'common/timestamps'
13
+ require_relative 'common/blocking_job'
14
+ require_relative 'postbuild'
15
+
16
+ module JenkinsJob
17
+ module Common
18
+ class Common
19
+ attr_reader :builder,
20
+ :node_, :quiet_period_, :logrotate_,
21
+ :parameters_, :postbuild_, :scm_,
22
+ :triggers_, :concurrent_, :wrappers_, :properties_,
23
+ :desc_
24
+
25
+ def initialize(builder)
26
+ @builder = builder
27
+ @triggers_ = {}
28
+ @wrappers_ = {}
29
+ @properties_ = {}
30
+ @parameters_ = {}
31
+ @concurrent_ = false
32
+ end
33
+
34
+ def node(value)
35
+ @node_ = value
36
+ end
37
+
38
+ def quiet_period(value)
39
+ @quiet_period_ = value
40
+ end
41
+
42
+ def logrotate(&block)
43
+ rotate = LogRotate.new
44
+ rotate.instance_eval(&block)
45
+ @logrotate_ = rotate
46
+ end
47
+
48
+ def parameter(name, &block)
49
+ param = Parameter.new(name)
50
+ param.instance_eval(&block) if block_given?
51
+
52
+ @parameters_[name] = param
53
+ end
54
+
55
+ def password_parameter(name, &block)
56
+ param = PasswordParameter.new(name)
57
+ param.instance_eval(&block) if block_given?
58
+
59
+ @parameters_[name] = param
60
+ end
61
+
62
+ def postbuild(&block)
63
+ @postbuild_ = ::JenkinsJob::Postbuild::Postbuild.new(self) unless @postbuild_
64
+ @postbuild_.instance_eval(&block)
65
+ end
66
+
67
+ def git(&block)
68
+ git = Git.new
69
+ git.instance_eval(&block)
70
+
71
+ @scm_ = git
72
+ end
73
+
74
+ def scms(&block)
75
+ scms = Scms.new
76
+ scms.instance_eval(&block)
77
+
78
+ @scm_ = scms
79
+ end
80
+
81
+ def gerrit(&block)
82
+ gerrit = Gerrit.new
83
+ gerrit.instance_eval(&block)
84
+
85
+ @triggers_['gerrit'] = gerrit
86
+ end
87
+
88
+ def pollscm(value)
89
+ @triggers_['pollscm'] = PollSCM.new(value)
90
+ end
91
+
92
+ def timed(value)
93
+ @triggers_['timed'] = Timed.new(value)
94
+ end
95
+
96
+ def concurrent(&block)
97
+ @concurrent_ = true
98
+
99
+ throttle = Throttle.new
100
+ throttle.instance_eval(&block)
101
+
102
+ @properties_['throttle'] = throttle
103
+ end
104
+
105
+ def timestamps
106
+ @wrappers_['timestamp'] = Timestamps.new
107
+ end
108
+
109
+ def timeout(type, &block)
110
+ build_timeout = BuildTimeout.new(type)
111
+ build_timeout.instance_eval(&block)
112
+
113
+ @wrappers_['timeout'] = build_timeout
114
+ end
115
+
116
+ def artifactory(&block)
117
+ artifact = Artifactory.new
118
+ artifact.instance_eval(&block)
119
+
120
+ @wrappers_['artifactory'] = artifact
121
+ end
122
+
123
+ def password(name, password)
124
+ password = Password.new(name, password)
125
+
126
+ @wrappers_['password'] = password
127
+ end
128
+
129
+ def blocked_by(*value)
130
+ blocking_job = BlockingJob.new(value)
131
+
132
+ @properties_['blocking_job'] = blocking_job
133
+ end
134
+
135
+ def desc(value)
136
+ @desc_ = value
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,95 @@
1
+ require_relative './jenkins_client'
2
+
3
+ module JenkinsJob
4
+ class Deployer
5
+ def initialize(*builder)
6
+ @builders = builder
7
+ end
8
+
9
+ def each(&block)
10
+ @builders.each do |b|
11
+ b.generate_xml do |name, xml, type|
12
+ yield name, xml, type if block
13
+ end
14
+ end
15
+ end
16
+
17
+ def generate_xml
18
+ outputdir = ARGV.find { |z| z =~ /--output-dir=/ }.to_s.split('=')[1]
19
+ usage unless outputdir
20
+
21
+ each do |name, xml, type|
22
+ path = "#{outputdir}/#{name}.xml"
23
+ $stdout.puts "creating #{type} #{path}"
24
+ File.open(path, 'w+') do |f|
25
+ f.write(xml)
26
+ end
27
+ end
28
+ end
29
+
30
+ def deploy(&block)
31
+ config_file = ARGV.find { |z| z =~ /--config-file=/ }.to_s.split('=')[1]
32
+ usage unless config_file
33
+
34
+ config = {}
35
+ File.read(config_file).each_line do |line|
36
+ if line =~ /\S+\=\S+/
37
+ key, val = line.split('=')
38
+ config[key] = val.chomp
39
+ end
40
+ end
41
+
42
+ client = JenkinsClient.new(config['url'], config['user'], config['password'])
43
+ deployer = self
44
+ client.instance_eval do
45
+ @deployer = deployer
46
+ def each(&block)
47
+ @deployer.each(&block)
48
+ end
49
+ end
50
+
51
+ unless block
52
+ block = proc do
53
+ each do |name, xml, type|
54
+ upload_job(name, xml) if type == :job
55
+ upload_view(name, xml) if type == :view
56
+ end
57
+ end
58
+ end
59
+
60
+ client.instance_eval(&block)
61
+ end
62
+
63
+ def usage
64
+ $stderr.puts(<<-EOS
65
+ Usage:
66
+
67
+ ruby #{File.basename($PROGRAM_NAME)} --xml --output-dir=.|--deploy --config-file=config/localhost.ini]
68
+
69
+ Example:
70
+
71
+ ruby #{File.basename($PROGRAM_NAME)} --xml --output-dir=.
72
+ ruby #{File.basename($PROGRAM_NAME)} --deploy --config-file=config/localhost.ini
73
+ EOS
74
+ )
75
+ exit 1
76
+ end
77
+
78
+ def run(&block)
79
+ xml = ARGV.find { |a| a == '--xml' }
80
+ deploy = ARGV.find { |a| a == '--deploy' }
81
+
82
+ if xml
83
+ generate_xml
84
+ exit 0
85
+ end
86
+
87
+ if deploy
88
+ deploy(&block)
89
+ exit 0
90
+ end
91
+
92
+ usage
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,14 @@
1
+ module JenkinsJob
2
+ class Flow < Common::Common
3
+ attr_reader :name, :dsl_
4
+
5
+ def initialize(name, builder)
6
+ super(builder)
7
+ @name = name
8
+ end
9
+
10
+ def dsl(value)
11
+ @dsl_ = value
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,57 @@
1
+ require_relative './common'
2
+ require_relative './buildstep/shell'
3
+ require_relative './buildstep/copyartifact'
4
+ require_relative './buildstep/inject_env'
5
+ require_relative './buildstep/ant'
6
+
7
+ module JenkinsJob
8
+ class FreeStyle < Common::Common
9
+ include BuildStep
10
+
11
+ attr_reader :name, :workspace_, :builders_
12
+
13
+ def initialize(name, builder)
14
+ super(builder)
15
+ @name = name
16
+ @builders_ = []
17
+ end
18
+
19
+ def workspace(value)
20
+ @workspace_ = value
21
+ end
22
+
23
+ def shell(cmd)
24
+ @builders_ << Shell.new(cmd)
25
+ end
26
+
27
+ def batch(cmd)
28
+ @builders_ << Batch.new(cmd)
29
+ end
30
+
31
+ def powershell(cmd)
32
+ @builders_ << Powershell.new(cmd)
33
+ end
34
+
35
+ def inject_env(&block)
36
+ inject = InjectEnv.new
37
+ inject.instance_eval(&block) if block_given?
38
+
39
+ @builders_ << inject
40
+ end
41
+
42
+ def ant(&block)
43
+ ant = Ant.new
44
+ ant.instance_eval(&block) if block_given?
45
+
46
+ @builders_ << ant
47
+ end
48
+
49
+ def copyartifact(artifact_job, &block)
50
+ # sandbox for copy artifacts dsl
51
+ copyartifact = CopyArtifact.new(artifact_job)
52
+ copyartifact.instance_eval(&block)
53
+
54
+ @builders_ << copyartifact
55
+ end
56
+ end
57
+ end