class Jujube::Job
Models a single Jenkins job.
Attributes
The job configuration.
All configuration is stored internally as a `Hash` with `String` keys in canonical jenkins-job-builder format. This format can readily be converted to the YAML needed by jenkins-job-builder.
Public Class Methods
Keep track of all `Job`s defined during the execution of the passed block.
This is used during job loading so that no extra syntax is required in the job definition files for registering jobs and so that it is possible to create jobs for testing purposes without having them registered anywhere.
@return [Array<Job>] Returns a list of all `Job`s defined within the block.
# File lib/jujube/job.rb, line 230 def self.all_defined_during @registry = [] yield @registry ensure @registry = [] end
Initialize the job.
Takes a configuration block for adding atributes and sections to the job. The configuration block is passed the new `Job` as a parameter.
@param job_name [String] The name of the job. Will be the name as seen in Jenkins. @yieldparam self [Job] Passes itself to the configuration block.
# File lib/jujube/job.rb, line 16 def initialize(job_name) @config = {} self.name = job_name yield(self) if block_given? self.class.register(self) end
Register a `Job` in a registry.
If no registry is active, this is a no-op.
@param job [Job] The job to register.
# File lib/jujube/job.rb, line 243 def self.register(job) @registry << job if @registry end
Public Instance Methods
Generate a `Hash` repsentation of the `Job`.
# File lib/jujube/job.rb, line 216 def to_h infer_project_type {'job' => config} end
Generate a YAML representation of the `Job`.
# File lib/jujube/job.rb, line 211 def to_yaml(*args) to_h.to_yaml(*args) end
Private Instance Methods
Have any `axes` been specified?
Take care to not lazily-initialize an `“axes”` key when checking.
@return [Boolean] `true` if any `axes` have been defined; `false` otherwise.
# File lib/jujube/job.rb, line 267 def has_axes? config.has_key?("axes") && !axes.empty? end
Set the {#project_type} to `matrix` if any `axes` have been specified.
# File lib/jujube/job.rb, line 258 def infer_project_type self.project_type = "matrix" if has_axes? end