require 'gitlab' require 'date' 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 '3000s', :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'], :default_branch => proj['default_branch']} end projects.each do |proj| begin pipelines = Gitlab.pipelines(proj[:id], { per_page: 10 }) #pp pipeline[0] 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' 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