Class: Jenkins::Model::Build

Inherits:
Object
  • Object
show all
Includes:
Plugin::Wrapper
Defined in:
lib/jenkins/model/build.rb

Overview

Represents a single build. This object is passed in to all build steps, and can be used to configure, halt, message the current running build.

Defined Under Namespace

Classes: EnvironmentVariables, Halt

Instance Attribute Summary collapse

Attributes included from Plugin::Wrapper

#native

Instance Method Summary collapse

Methods included from Plugin::Behavior

extended, #implemented, #included

Methods included from Plugin::Behavior::BehavesAs

#behaves_as

Constructor Details

#initialize(native) ⇒ Build

Returns a new instance of Build.



31
32
33
34
35
36
# File 'lib/jenkins/model/build.rb', line 31

def initialize(native)
  super(native)
  @variables = {}
  @env = {}
  @native.buildEnvironments.add(EnvironmentVariables.new(@env))
end

Instance Attribute Details

#envObject (readonly)

Hash of environment variables that will be added to each process started as part of this build. E.g.

build.env = ‘/path/to/my/gem/home’

Note that this is not an exhaustive list of all environment variables, only those which have been explicitly set by code inside this Ruby plugin.

Also, this list does not contain variables that might get set by things like .profile and .rc files.



29
30
31
# File 'lib/jenkins/model/build.rb', line 29

def env
  @env
end

Instance Method Details

#[](key) ⇒ Object

Gets a build value. Each build stores a map of key,value pairs which can be used by each build step in the pipeline

Parameters:

  • key (String|Symbol)

Returns:

  • (Object)

    value



43
44
45
# File 'lib/jenkins/model/build.rb', line 43

def [](key)
  @variables[key.to_s]
end

#[]=(key, value) ⇒ Object

Sets a build value. Each build has a map of key,value pairs which allow build steps to share information

Parameters:

  • key (String|Symbol)
  • value (Object)

Returns:

  • (Object)

    value



53
54
55
# File 'lib/jenkins/model/build.rb', line 53

def []=(key, value)
  @variables[key.to_s] = value
end

#abort(reason = nil) ⇒ Object

Abort the current build, causing a build failure.

Parameters:

  • reason (String) (defaults to: nil)

    the reason for your abort, optional.

Raises:

  • (Java.hudson.AbortException)


73
74
75
# File 'lib/jenkins/model/build.rb', line 73

def abort(reason = nil)
  raise Java.hudson.AbortException.new(reason)
end

#halt(reason = nil) ⇒ Object

Halt the current build, without setting the result to failure

Parameters:

  • reason (String) (defaults to: nil)

    the reason for your halt, optional.

Raises:



66
67
68
# File 'lib/jenkins/model/build.rb', line 66

def halt(reason = nil)
  raise Halt, reason
end

#workspaceJenkins::FilePath

The workspace associated with this build

Returns:



59
60
61
# File 'lib/jenkins/model/build.rb', line 59

def workspace
  FilePath.new(@native.getWorkspace())
end