jenkins-plugin-runtime 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,11 +2,17 @@ require 'jenkins/filepath'
2
2
 
3
3
  module Jenkins
4
4
  module Model
5
+
5
6
  ##
6
7
  # Represents a single build. In general, you won't need this
7
8
  #
8
9
  class Build
9
10
 
11
+ # Raised to indicate that a build wrapper halted a build.
12
+ # Raising this does *not* set the build result to error.
13
+ class Halt < Exception; end
14
+
15
+
10
16
  # the Hudson::Model::AbstractBuild represented by this build
11
17
  attr_reader :native
12
18
 
@@ -18,6 +24,20 @@ module Jenkins
18
24
  FilePath.new(@native.getWorkspace())
19
25
  end
20
26
 
27
+ # Halt the current build, without setting the result to failure
28
+ #
29
+ # @param [String] reason the reason for your halt, optional.
30
+ def halt(reason = nil)
31
+ raise Halt, reason
32
+ end
33
+
34
+ # Abort the current build, causing a build failure.
35
+ #
36
+ # @param [String] reason the reason for your abort, optional.
37
+ def abort(reason = nil)
38
+ raise Java.hudson.AbortException.new(reason)
39
+ end
40
+
21
41
  def build_var
22
42
  @native.getBuildVariables()
23
43
  end
@@ -7,7 +7,7 @@ module Jenkins
7
7
  class Listener
8
8
 
9
9
  # the underlying hudson.model.TaskListener object
10
- attr_reader :natvie
10
+ attr_reader :native
11
11
  attr_accessor :level
12
12
 
13
13
  def initialize(native = nil)
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'jenkins/tasks/build_wrapper'
3
+ require 'jenkins/model/build'
3
4
 
4
5
  module Jenkins
5
6
  class Plugin
@@ -17,6 +18,8 @@ module Jenkins
17
18
  env = {}
18
19
  @object.setup(import(build), import(launcher), import(listener), env)
19
20
  EnvironmentWrapper.new(self, @plugin, @object, env)
21
+ rescue Jenkins::Model::Build::Halt
22
+ nil
20
23
  end
21
24
 
22
25
  def getDescriptor
@@ -1,7 +1,7 @@
1
1
  module Jenkins
2
2
  class Plugin
3
3
  module Runtime
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.9"
5
5
  end
6
6
  end
7
7
  end
@@ -3,7 +3,6 @@ require 'jenkins/model'
3
3
 
4
4
  module Jenkins
5
5
  module Tasks
6
-
7
6
  # Decorate a build with pre and post hooks.
8
7
  # {http://javadoc.jenkins-ci.org/hudson/tasks/BuildWrapper.html}
9
8
  class BuildWrapper
@@ -36,4 +35,4 @@ module Jenkins
36
35
  end
37
36
  end
38
37
  end
39
- end
38
+ end
@@ -1,10 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Jenkins::Model::Build do
4
+ include Jenkins::Model
4
5
 
5
6
  before :each do
6
7
  @native = mock("AbstractBuild")
7
- @subject = Jenkins::Model::Build.new(@native)
8
+ @build = Jenkins::Model::Build.new(@native)
8
9
  end
9
10
 
10
11
  it "can be instantiated" do
@@ -15,16 +16,24 @@ describe Jenkins::Model::Build do
15
16
  fs = Jenkins::FilePath.new(nil)
16
17
  fs.should_receive(:getRemote).and_return(".")
17
18
  @native.should_receive(:getWorkspace).and_return(fs)
18
- @subject.workspace.to_s.should == "."
19
+ @build.workspace.to_s.should == "."
19
20
  end
20
21
 
21
22
  it "returns build variables as Hash-like" do
22
23
  @native.should_receive(:getBuildVariables).and_return("FOO" => "BAR")
23
- @subject.build_var.should == {"FOO" => "BAR"}
24
+ @build.build_var.should == {"FOO" => "BAR"}
24
25
  end
25
26
 
26
27
  it "returns environment variables as Hash-like" do
27
28
  @native.should_receive(:getEnvironment).with(nil).and_return("FOO" => "BAR")
28
- @subject.env.should == {"FOO" => "BAR"}
29
+ @build.env.should == {"FOO" => "BAR"}
30
+ end
31
+
32
+ it "can halt" do
33
+ expect {@build.halt "stopping"}.should raise_error(Jenkins::Model::Build::Halt, "stopping")
34
+ end
35
+
36
+ it "can abort" do
37
+ expect {@build.abort "aborting"}.should raise_error(Java.hudson.AbortException, "aborting")
29
38
  end
30
39
  end
@@ -22,4 +22,14 @@ describe Jenkins::Plugin::Proxies::BuildWrapper do
22
22
  @object.should_receive(:teardown).with(@build, @listener, env)
23
23
  environment.tearDown(@jBuild, @jListener)
24
24
  end
25
+
26
+ describe "halting behavior" do
27
+ before do
28
+ @object.stub(:setup).and_raise(Jenkins::Model::Build::Halt)
29
+ end
30
+
31
+ it "returns false if the build was halted explicitly" do
32
+ @wrapper.setUp(@jBuild, @jLauncher, @jListener).should be_nil
33
+ end
34
+ end
25
35
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jenkins-plugin-runtime
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.8
5
+ version: 0.1.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Charles Lowell
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-01 00:00:00 -05:00
13
+ date: 2011-10-26 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency