diff options
Diffstat (limited to 'jobs')
-rw-r--r-- | jobs/gitlab_build_status.rb | 44 | ||||
-rw-r--r-- | jobs/gitlab_builds.rb | 66 |
2 files changed, 44 insertions, 66 deletions
diff --git a/jobs/gitlab_build_status.rb b/jobs/gitlab_build_status.rb new file mode 100644 index 0000000..addfaed --- /dev/null +++ b/jobs/gitlab_build_status.rb @@ -0,0 +1,44 @@ +require 'gitlab' +require 'date' +require 'pp' + +Gitlab.configure do |config| + # API endpoint URL, default + config.endpoint = ENV['GITLAB_ENDPOINT'] + + # User's private token or OAuth2 access token + config.private_token = ENV['GITLAB_TOKEN'] +end + +SCHEDULER.every '300s', :first_in => 0 do + broken_builds = [] + + # 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'] } + end + + projects.each do |proj| + + begin + pipeline = Gitlab.pipelines(proj[:id], { per_page: 1 }) + #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") + proj[:date] = date + rescue + proj[:status] = 'No builds configured' + end + + unless proj[:status] =~ /^success|running|No builds configured$/ + broken_builds << proj + end + puts proj + end + + failed = broken_builds.size > 0 + + send_event('gitlab-builds', { failed: failed, header: "Gitlab builds", broken_builds: broken_builds }) +end diff --git a/jobs/gitlab_builds.rb b/jobs/gitlab_builds.rb deleted file mode 100644 index 0071835..0000000 --- a/jobs/gitlab_builds.rb +++ /dev/null @@ -1,66 +0,0 @@ -require 'gitlab' -require 'date' -require 'pp' - -endpoint = 'https://0xacab.org/api/v3' -#group_path = 'leap' -#group_id = 52 -token = '8vw3vWRrzFw8B6XH9e6d' -broken_builds = [] - -Gitlab.configure do |config| - # API endpoint URL, default - config.endpoint = endpoint - - # User's private token or OAuth2 access token - config.private_token = token -end - -# find group id by name -#my_group = Gitlab.groups(:search => group_path).find do |group| - #group.path == group_path -#end -#my_group_id = my_group.id - - -SCHEDULER.every '60s', :first_in => 0 do - - projects = [ - # {:id=>327, :name=>"zeromq3", :path=>"leap/zeromq3"}, - # {:id=>97, :name=>"soledad", :path=>"leap/soledad"}, - # {:id=>129, :name=>"platform", :path=>"leap/platfrom"}, - {:id=>241, :name=>"leap_cli", :path=>"leap/leap_cli"} - ] - - # get a list of all projects - #projects = Gitlab.group(group_id).projects.map do |proj| - #pp proj - #{ :id => proj['id'], :name => proj['name'], :path => proj['path_with_namespace'] } - #end - - - projects.each do |proj| - - begin - pipeline = Gitlab.pipelines(proj[:id], { per_page: 1 }) - #pp pipeline[0] - proj[:status] = pipeline[0].status - proj[:pipeline_id] = pipeline[0].id - proj[:ref] = pipeline[0].ref - proj[:date] = pipeline[0].finished_at - rescue - proj[:status] = 'No builds configured' - end - - unless proj[:status] =~ /^success|running|No builds configured$/ - broken_builds << proj - end - puts proj - end - - failed = broken_builds.size > 0 - #puts failed - - send_event('gitlab-builds', { failed: failed, header: "Gitlab builds", broken_builds: broken_builds }) -end - |