gem 'gocd'
or
gem install gocd
http://www.rubydoc.info/gems/gocd/1.3
GOCD.server = GOCD::Server.new 'http://goserverurl.com'
GOCD.credentials = GOCD::Credentials.new 'username', 'password'
GOCD::AllPipelines.red_pipelines
pipelines = GOCD::PipelineGroup.new ['Pipeline1 :: stage1', 'Pipeline1 :: stage2', 'Pipeline2 :: stage1']
pipelines.red_pipelines
pipelines.status
pipelines.any_red?
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 pipelines
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
end
idle_agents = GOCD::Agents.idle
idle_agents.each { |agent| agent.name }
GOCD::Agents.missing
GOCD::Agents.disabled
include GOCD::PIPELINE_CONFIG
environments #returns all the environments and the whole hierarchy of it
include GOCD::PIPELINE_CONFIG
pipelines = environments.map(&:pipelines).flatten
include GOCD::PIPELINE_CONFIG
stages = environments.map(&:pipelines).flatten.map(&:stages).flatten
include GOCD::PIPELINE_CONFIG
jobs = environments.map(&:pipelines).flatten.map(&:stages).flatten.map(&:jobs).flatten
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)
end
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.