Ubuntu Pastebin

Paste from magic at Tue, 3 Feb 2015 14:54:55 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'optparse'
require 'jenkins_api_client'
require 'thwait'

options = {}

OptionParser.new do | opts |
  opts.banner = "Usage: retry.rb job_filter"

  opts.on("-f", "--force", "Force build") do | v |
    options[:force] = v
  end
end.parse!

@client = JenkinsApi::Client.new( :server_ip => 'dci.pangea.pub', :username => '', :password => '', :jenkins_path => "/job/plasma/" )
@client_without_path = JenkinsApi::Client.new( :server_ip => 'dci.pangea.pub', :username => '', :password => '' )

jobs = @client.job.list(ARGV[0])

threads = []
jobs.each do | job |
        threads << Thread.new do
  upstream_failed = false
    tries ||= 10
    begin
      if @client.job.status(job) == 'failure' or options[:force] and
        not @client_without_path.queue.list.include?(job)
        @client.job.get_upstream_projects(job).each do | upstream_job |
          status = @client.job.color_to_status(upstream_job['color'])
          if status == 'failure'
            upstream_failed = true
          end
        end
        @client.job.build(job) unless upstream_failed
      end
    rescue Timeout::Error => _e
      if (tries -= 1) > 0
        sleep(30.seconds)
        retry
      end
    end
  end
end

ThreadsWait.all_waits(threads)
Download as text