Class: Jenkins::JobConfigBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins/job_config_builder.rb

Constant Summary collapse

InvalidTemplate =
Class.new(StandardError)
VALID_JOB_TEMPLATES =
%w[none rails rails3 ruby rubygem erlang]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_type = :ruby) {|_self| ... } ⇒ JobConfigBuilder

job_type - template of default steps to create with the job steps - array of [:method, cmd], e.g. [:build_shell_step, “bundle initial”]

- Default is based on +job_type+.

scm - URL to the repository. Currently only support git URLs. public_scm - convert the scm URL to a publicly accessible URL for the Jenkins job config. scm_branches - array of branches to run builds. Default: [‘master’] rubies - list of RVM rubies to run tests (via Jenkins Axes). assigned_node - restrict this job to running on slaves with these labels (space separated)

Yields:

  • (_self)

Yield Parameters:

Raises:



24
25
26
27
28
29
30
31
# File 'lib/jenkins/job_config_builder.rb', line 24

def initialize(job_type = :ruby, &block)
  self.job_type = job_type.to_s if job_type
  
  yield self

  self.scm_branches ||= ["master"]
  raise InvalidTemplate unless VALID_JOB_TEMPLATES.include?(job_type.to_s)
end

Instance Attribute Details

#assigned_nodeObject

TODO just one of these



9
10
11
# File 'lib/jenkins/job_config_builder.rb', line 9

def assigned_node
  @assigned_node
end

#envfileObject

Returns the value of attribute envfile.



10
11
12
# File 'lib/jenkins/job_config_builder.rb', line 10

def envfile
  @envfile
end

#git_branchesObject

Returns the value of attribute git_branches.



8
9
10
# File 'lib/jenkins/job_config_builder.rb', line 8

def git_branches
  @git_branches
end

#job_typeObject

Returns the value of attribute job_type.



5
6
7
# File 'lib/jenkins/job_config_builder.rb', line 5

def job_type
  @job_type
end

#node_labelsObject

TODO just one of these



9
10
11
# File 'lib/jenkins/job_config_builder.rb', line 9

def node_labels
  @node_labels
end

#public_scmObject

Returns the value of attribute public_scm.



7
8
9
# File 'lib/jenkins/job_config_builder.rb', line 7

def public_scm
  @public_scm
end

#rubiesObject

Returns the value of attribute rubies.



6
7
8
# File 'lib/jenkins/job_config_builder.rb', line 6

def rubies
  @rubies
end

#scmObject

Returns the value of attribute scm.



7
8
9
# File 'lib/jenkins/job_config_builder.rb', line 7

def scm
  @scm
end

#scm_branchesObject

Returns the value of attribute scm_branches.



7
8
9
# File 'lib/jenkins/job_config_builder.rb', line 7

def scm_branches
  @scm_branches
end

#stepsObject

Returns the value of attribute steps.



6
7
8
# File 'lib/jenkins/job_config_builder.rb', line 6

def steps
  @steps
end

Instance Method Details

#builderObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/jenkins/job_config_builder.rb', line 33

def builder
  b = Builder::XmlMarkup.new :indent => 2
  b.instruct!
  b.tag!(matrix_project? ? "matrix-project" : "project") do
    b.actions
    b.description
    b.keepDependencies false
    b.properties
    build_scm b
    b.assignedNode assigned_node if assigned_node
    b.canRoam !assigned_node
    b.disabled false
    b.blockBuildWhenUpstreamBuilding false
    b.triggers :class => "vector"
    b.concurrentBuild false
    build_axes b if matrix_project?
    build_steps b
    b.publishers
    build_wrappers b
    b.runSequentially false if matrix_project?
  end
end

#to_xmlObject



56
57
58
# File 'lib/jenkins/job_config_builder.rb', line 56

def to_xml
  builder.to_s
end