Class: Hudson::JobConfigBuilder

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

Constant Summary collapse

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

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 Hudson job config. git_branches - array of branches to run builds. Default: [‘master’] assigned_node - restrict this job to running on slaves with these labels (space separated)

Yields:

  • (_self)

Yield Parameters:

Raises:



22
23
24
25
26
27
28
29
# File 'lib/hudson/job_config_builder.rb', line 22

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

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

Instance Attribute Details

#assigned_nodeObject

Returns the value of attribute assigned_node.



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

def assigned_node
  @assigned_node
end

#envfileObject

Returns the value of attribute envfile.



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

def envfile
  @envfile
end

#git_branchesObject

Returns the value of attribute git_branches.



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

def git_branches
  @git_branches
end

#job_typeObject

Returns the value of attribute job_type.



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

def job_type
  @job_type
end

#matrix_projectObject

Returns the value of attribute matrix_project.



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

def matrix_project
  @matrix_project
end

#public_scmObject

Returns the value of attribute public_scm.



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

def public_scm
  @public_scm
end

#scmObject

Returns the value of attribute scm.



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

def scm
  @scm
end

#stepsObject

Returns the value of attribute steps.



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

def steps
  @steps
end

Instance Method Details

#builderObject



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

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
    # build_triggers b
    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



54
55
56
# File 'lib/hudson/job_config_builder.rb', line 54

def to_xml
  builder.to_s
end