gocd
Installation
gem 'gocd'or
gem install gocdCode Documentation
http://www.rubydoc.info/gems/gocd/1.3
Usage
GOCD.server = GOCD::Server.new 'http://goserverurl.com'
GOCD.credentials = GOCD::Credentials.new 'username', 'password'To check all pipelines:
GOCD::AllPipelines.red_pipelinesTo check a group of pipelines:
pipelines = GOCD::PipelineGroup.new ['Pipeline1 :: stage1', 'Pipeline1 :: stage2', 'Pipeline2 :: stage1']
pipelines.red_pipelines
pipelines.status
pipelines.any_red?Cache
By default all methods in GOCD::AllPipelines and GOCD::PipelineGroup make a call to go api to fetch the latest status of pipelines. This can be avoided using cache. To enable cache just pass cache: true when you call any of the method in GOCD::AllPipelines and GOCD::PipelineGroup.
GOCD::AllPipelines.any_red?(cache: true)
GOCD::AllPipelines.red_pipelines(cache: true)
GOCD::AllPipelines.green_pipelines(cache: true)
GOCD::AllPipelines.status(cache: true)pipelines = GOCD::PipelineGroup.new(['Pipeline1 :: stage1'], cache: true)
pipelines.red_pipelines # will return red pipelines from cache
pipelines.status # will return pipelines status from cache
pipelines.any_red?(cache: false) # will check with the latest pipelinesWant to create your own gocd dashboard? Its easy now!
require 'sinatra'
require 'gocd'
get '/' do
GOCD.server = GOCD::Server.new 'http://goserverurl.com'
GOCD.credentials = GOCD::Credentials.new 'username', 'password'
GOCD::AllPipelines.red_pipelines(cache: false).map {|pipeline| pipeline.to_hash}.to_json
endGo Agents
To get all the idle agents:
idle_agents = GOCD::Agents.idle
idle_agents.each { |agent| agent.name }To get all the missing agents:
GOCD::Agents.missingTo get all the disabled agents:
GOCD::Agents.disabledPipeline Configuration
Get all the environments
include GOCD::PIPELINE_CONFIG
environments #returns all the environments and the whole hierarchy of itGet all the pipelines
include GOCD::PIPELINE_CONFIG
pipelines = environments.map(&:pipelines).flattenGet all the stages
include GOCD::PIPELINE_CONFIG
stages = environments.map(&:pipelines).flatten.map(&:stages).flattenGet all the jobs
include GOCD::PIPELINE_CONFIG
jobs = environments.map(&:pipelines).flatten.map(&:stages).flatten.map(&:jobs).flattenHistory Fetcher
You can fetch history of a job using the HistoryFetcher APIs
require 'gocd'
GOCD.server = GOCD::Server.new 'http://goserverurl.com'
GOCD.credentials = GOCD::Credentials.new 'username', 'password'
include GOCD::PIPELINE_CONFIG
histories = []
runs = 1000
jobs = environments.map(&:pipelines).flatten.map(&:stages).flatten.map(&:jobs).flatten
jobs.each do |job|
histories << GOCD::HistoryFetcher.fetch_job_history(job, runs)
endLICENSE
Copyright (C) 2016 Ajit Singh
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.