Class: GOCD::HistoryFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gocd/history/history_fetcher.rb

Class Method Summary collapse

Class Method Details

.fetch_job_history(job, runs = 100) ⇒ Object



7
8
9
10
# File 'lib/gocd/history/history_fetcher.rb', line 7

def self.fetch_job_history(job, runs=100)
  response = fetch_raw_job_history(job, runs)
  CSV.parse(response, headers: true).map { |line| line.to_hash } unless response.nil?
end

.fetch_raw_job_history(job, runs = 100) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gocd/history/history_fetcher.rb', line 12

def self.fetch_raw_job_history(job, runs=100)
  params = {pipelineName: job.pipeline, stageName: job.stage, jobName: job.name, limitPipeline: 'latest', limitCount: runs}
  params = URI.encode_www_form(params)
  request = {
      method: :get,
      url: "#{GOCD.server.url}/go/properties/search?#{params}",
      user: GOCD.credentials.username,
      password: GOCD.credentials.password,
  }

  begin
    res = RestClient::Request.execute(request)
    response = res.body unless res.nil?
  rescue => e
    error = <<-ERROR
      Could not fetch history for #{job.pipeline}::#{job.stage}::#{job.name}
      Response received from server: #{e}
    ERROR
    response = nil
    puts error
  end
  response
end