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]
JOB_TRIGGER_THRESHOLDS =
{
  "SUCCESS"  => {:ordinal => 0, :color => "BLUE"},
  "UNSTABLE" => {:ordinal => 1, :color => "YELLOW"},
  "FAILURE"  => {:ordinal => 2, :color => "RED"}
}

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). triggers - list of triggers to start the build. Currently only support time triggers assigned_node - restrict this job to running on slaves with these labels (space separated) publishers - define publishers to be performed after a build log_rotate - define log rotation

Yields:

  • (_self)

Yield Parameters:

Raises:



34
35
36
37
38
39
40
41
# File 'lib/jenkins/job_config_builder.rb', line 34

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



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

def assigned_node
  @assigned_node
end

#envfileObject

Returns the value of attribute envfile.



12
13
14
# File 'lib/jenkins/job_config_builder.rb', line 12

def envfile
  @envfile
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

#log_rotateObject

Returns the value of attribute log_rotate.



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

def log_rotate
  @log_rotate
end

#node_labelsObject

TODO just one of these



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

def node_labels
  @node_labels
end

#public_scmObject

Returns the value of attribute public_scm.



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

def public_scm
  @public_scm
end

#publishersObject

Returns the value of attribute publishers.



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

def publishers
  @publishers
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.



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

def scm
  @scm
end

#scm_branchesObject

Returns the value of attribute scm_branches.



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

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

#triggersObject

Returns the value of attribute triggers.



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

def triggers
  @triggers
end

#user_axesObject

Returns the value of attribute user_axes.



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

def user_axes
  @user_axes
end

Instance Method Details

#builderObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/jenkins/job_config_builder.rb', line 43

def builder
  b = Builder::XmlMarkup.new :indent => 2
  b.instruct!
  b.tag!(matrix_project? ? "matrix-project" : "project") do
    b.actions
    b.description
    build_log_rotator b
    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
    build_publishers b
    build_wrappers b
    b.runSequentially false if matrix_project?
  end
end

#to_xmlObject



67
68
69
# File 'lib/jenkins/job_config_builder.rb', line 67

def to_xml
  builder.to_s
end