Giter Site home page Giter Site logo

ajitsing / gocd Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 5.0 74 KB

Gem to fetch gocd information easily

Home Page: http://www.singhajit.com/ruby-gem-to-fetch-information-gocd-rich-models/

License: Apache License 2.0

Ruby 100.00%
ci continuous-integration continuous-delivery continuous-deployment ruby gem rubygem gocd goconfig pipeline

gocd's Introduction

gocd

Maintenance Open Source Love Gem Version HitCount Gem Downloads Build Status Twitter Follow

Installation

gem 'gocd'

or

gem install gocd

Code 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_pipelines
To 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 pipelines

Want 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
end

Go 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.missing
To get all the disabled agents:
GOCD::Agents.disabled

Pipeline Configuration

Get all the environments
include GOCD::PIPELINE_CONFIG

environments #returns all the environments and the whole hierarchy of it
Get all the pipelines
include GOCD::PIPELINE_CONFIG

pipelines = environments.map(&:pipelines).flatten
Get all the stages
include GOCD::PIPELINE_CONFIG

stages = environments.map(&:pipelines).flatten.map(&:stages).flatten
Get all the jobs
include GOCD::PIPELINE_CONFIG

jobs = environments.map(&:pipelines).flatten.map(&:stages).flatten.map(&:jobs).flatten

History 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)
end

LICENSE

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.

gocd's People

Contributors

ajitsing avatar jainsahab avatar varunrocks6 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gocd's Issues

Data refresh

This may be a silly question but is there a way to get the pipeline status to update? I wrote a widget for Smashing to watch pipelines but I found that the statuses never change.

Digging around I found that in lib/gocd/pipeline_status/pipeline_repository.rb it looks as though all the data is collected once at the start and then never reloaded. Is this intended?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.