Top Level Namespace
Defined Under Namespace
Modules: JenkinsGrowler
Instance Method Summary collapse
- #build_status(job) ⇒ Object
- #changed_recently(buildTime, job) ⇒ Object
- #last_build_output(job) ⇒ Object
Instance Method Details
#build_status(job) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/jenkinsgrowler.rb', line 54 def build_status(job) buildOutput = last_build_output job building = buildOutput['building'] buildTime = buildOutput['id'] duration = buildOutput['duration'] result = buildOutput['result'] description = buildOutput['fullDisplayName'] url = buildOutput['url'] comments = '' buildOutput['changeSet']['items'].each do |item| comments += item['comment'] end puts "#{result}, #{description}, #{url}\n#{comments}" if building or !changed_recently(buildTime, job) then return end %x[ growlnotify -n 'Jenkins' -t "#{result}" -m "#{description}\n#{comments}" --image "#{Dir.pwd}/lib/images/icon_64x64.png" -s --url "#{$ciBaseUrl}/job/#{job}/lastBuild"] end |
#changed_recently(buildTime, job) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jenkinsgrowler.rb', line 38 def changed_recently(buildTime, job) buildRunTime = DateTime.strptime("#{buildTime}#{$timezone}", '%Y-%m-%d_%H-%M-%S%z') if $jobRuns[job] == nil then $jobRuns[job] = buildRunTime return false end if buildRunTime > $jobRuns[job] then $jobRuns[job] = buildRunTime return true end return false end |
#last_build_output(job) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jenkinsgrowler.rb', line 19 def last_build_output(job) uri = URI.parse("#{$ciBaseUrl}/job/#{job}/lastBuild/api/json") http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Get.new(uri.request_uri) if ($username !=nil && $password != nil) then request.basic_auth($username, $password) end res = http.request(request) if(res.is_a? Net::HTTPClientError) then puts "#{Time.now} - Error: Not able to read the #{job} status, failed with error [#{res.}]" puts" Make sure the basic authorization credentials are provided, if the site is protected or the job names given are right." exit end JSON.parse res.body end |