From 6193bef96b118ca099c6a03bbe6403e0d4acd1ff Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 17 Jul 2017 20:51:46 +0200 Subject: feat: only alert for failing master builds --- jobs/gitlab_build_status.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'jobs') diff --git a/jobs/gitlab_build_status.rb b/jobs/gitlab_build_status.rb index be52f98..317118d 100644 --- a/jobs/gitlab_build_status.rb +++ b/jobs/gitlab_build_status.rb @@ -14,18 +14,20 @@ SCHEDULER.every '3000s', :first_in => 0 do # get a list of all projects projects = Gitlab.group(ENV['GITLAB_GROUP_ID']).projects.map do |proj| - { :id => proj['id'], :name => proj['name'], :path => proj['path_with_namespace'] } + { :id => proj['id'], :name => proj['name'], :path => proj['path_with_namespace'], + :default_branch => proj['default_branch']} end projects.each do |proj| - begin - pipeline = Gitlab.pipelines(proj[:id], { per_page: 1 }) + pipelines = Gitlab.pipelines(proj[:id], { per_page: 10 }) #pp pipeline[0] - proj[:status] = pipeline[0].status - proj[:pipeline_id] = pipeline[0].id - proj[:ref] = pipeline[0].ref - date = DateTime.parse(pipeline[0].updated_at).strftime("%F %T") + pipeline = pipelines.find{|p| p.ref == proj[:default_branch]} + next if pipeline.nil? + proj[:status] = pipeline.status + proj[:pipeline_id] = pipeline.id + proj[:ref] = pipeline.ref + date = DateTime.parse(pipeline.updated_at).strftime("%F %T") proj[:date] = date rescue proj[:status] = 'No builds configured' @@ -34,7 +36,7 @@ SCHEDULER.every '3000s', :first_in => 0 do unless proj[:status] =~ /^success|running|No builds configured$/ broken_builds << proj end - #puts proj + puts proj end failed = broken_builds.size > 0 -- cgit v1.2.3