Class: Jenkins::Build::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins/build/client.rb

Defined Under Namespace

Classes: InvalidResponse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jenkins/build/client.rb', line 8

def initialize(configuration)
  @configuration = configuration

  @base_uri = URI(@configuration.server).freeze

  @connection = Net::HTTP.new(@base_uri.host, @base_uri.port)
  @connection.use_ssl = (@base_uri.scheme == 'https')

  if ENV['DEBUG']
    @connection.set_debug_output $stderr
  end

  @connection
end

Instance Method Details

#test_report(number: 'lastBuild'.freeze, project: @configuration.project, builder: TestReport::Builder.new) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/jenkins/build/client.rb', line 36

def test_report(number: 'lastBuild'.freeze, project: @configuration.project, builder: TestReport::Builder.new)
  response = get("/job/#{project}/#{number}/testReport/api/json")

  case response
    when Net::HTTPOK then builder.build_report(JSON.parse response.body)
    else
      raise InvalidResponse, response
  end
end

#trigger(branch, parameters = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jenkins/build/client.rb', line 23

def trigger(branch, parameters = {})
  params = parameters.merge(sha1: branch).map do |key, value|
    { name: key, value: value }
  end

  response = post_json("/job/#{@configuration.project}/build", parameter: params)
  case response
    when Net::HTTPCreated then true
    else
      raise InvalidResponse, response
  end
end