jenkins-centaur 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a7bde381b15888916eefec46734597ae573ddd71
4
+ data.tar.gz: f4308c61ac83edb2bd074f9b36d38f62318f6669
5
+ SHA512:
6
+ metadata.gz: f3b5abc0c5f0e4731ee5e0b9ced61b970205f29089f61c639f7f367a134b9984e42670077f4f9894db6e85cef49108aa137d8e288abd2e4eba705c99d6e6f6d6
7
+ data.tar.gz: 25733102857760feeb88b55f272058a55a0c789559f23b1522ef5867947f3c51862fcd4ebfd0056687d4f9668ca59a2e4d0d7ddf46ee898dadcac295aa908d19
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2018 Daniel Han <hex0ctor@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # Jenkins Centaur
2
+
3
+ This Ruby gem allows you to start your jenkins jobs in batch from command line.
4
+
5
+ ## How to install it
6
+
7
+ ```bash
8
+ gem install jenkins-centaur
9
+ ```
10
+
11
+ ## How to run jenkins jobs
12
+
13
+ ```bash
14
+ jenkins-centaur run <yaml>
15
+ ```
16
+
17
+ Your yaml file defines the list of jobs you want to run. Below is an example of it:
18
+
19
+ ```yaml
20
+ server_url: https://jenkins.internal.xxxx.net
21
+ jobs:
22
+ - name: job_name
23
+ params:
24
+ param1: value1
25
+ param2: value2
26
+ ```
27
+
28
+ ## License
29
+
30
+ This code is free to use under the terms of the MIT license.
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'jenkins-centaur'
4
+ require 'thor'
5
+
6
+ class JenkinsCentaurCLI < Thor
7
+ desc "start <yaml>", "Download the mp3 according to the yaml file"
8
+ option :yaml
9
+ def start(yaml)
10
+ JenkinsCentaur::Centaur.new(yaml).start
11
+ end
12
+ end
13
+
14
+ JenkinsCentaurCLI.start(ARGV)
@@ -0,0 +1 @@
1
+ require 'jenkins-centaur/centaur'
@@ -0,0 +1,84 @@
1
+ require 'yaml'
2
+ require 'jenkins_api_client'
3
+ require 'concurrent'
4
+ require 'timeout'
5
+
6
+ module JenkinsCentaur
7
+ class Centaur
8
+ def initialize(resource)
9
+ raise "File '#{resource}' doesn't exist!" unless File.exist?(resource)
10
+
11
+ @config = YAML::load(File.open(resource))
12
+ raise "Invalid yaml file: '#{resource}'" unless @config
13
+
14
+ @client = JenkinsApi::Client.new(server_url: @config['server_url'])
15
+ @client.logger = Logger.new('jenkins_api_client.log', 10, 10_024_000)
16
+ end
17
+
18
+ def start
19
+ println "Started at: #{Time.now}."
20
+
21
+ build_info = Concurrent::Array.new
22
+ threads = []
23
+ @config['jobs'].each do |job|
24
+ threads << Thread.new do
25
+ println "Creating build for job #{job['name']} with parameters: #{job['params']}"
26
+
27
+ params = {}
28
+ job['params'].each do |key, value|
29
+ if value.include?('ENV')
30
+ params[key] = eval(value)
31
+ else
32
+ params[key] = value
33
+ end
34
+ end
35
+
36
+ build_num = @client.job.build(job['name'], params, 'build_start_timeout' => 300, 'poll_interval' => 10)
37
+ println "Created build #{build_num} for job #{job['name']} with parameters: #{job['params']}"
38
+
39
+ build_info << {build_num: build_num, job_name: job['name']}
40
+ end
41
+ end
42
+
43
+ threads.each(&:join)
44
+
45
+ overall_status = 0
46
+ build_info.each do |build|
47
+ build_num = build[:build_num]
48
+ job_name = build[:job_name]
49
+
50
+ build_details = nil
51
+ loop do
52
+ println "Checking build #{build_num}..."
53
+
54
+ begin
55
+ Timeout.timeout(10) do
56
+ build_details = @client.job.get_build_details(job_name, build_num)
57
+ end
58
+ rescue StandardError => e
59
+ println "Exception occured while trying to check the result, will check again soon. #{e.message}"
60
+ sleep 5
61
+ end
62
+
63
+ break if build_details['result']
64
+ sleep(2)
65
+ end
66
+
67
+ println "Results for build #{build_num}: #{build_details['result']}. See more at: #{build_details['url']}"
68
+
69
+ overall_status = 1 if build_details['result'] != 'SUCCESS'
70
+ end
71
+
72
+ println "All done at #{Time.now}."
73
+
74
+ overall_status
75
+ end
76
+
77
+ private
78
+
79
+ def println(text)
80
+ puts text
81
+ STDOUT.flush
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module JenkinsCentaur
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jenkins-centaur
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Han
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jenkins_api_client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.19'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.19'
41
+ description: Start jenkins jobs in batch from command line
42
+ email: hex0cter@gmail.com
43
+ executables:
44
+ - jenkins-centaur
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE.md
49
+ - README.md
50
+ - bin/jenkins-centaur
51
+ - lib/jenkins-centaur.rb
52
+ - lib/jenkins-centaur/centaur.rb
53
+ - lib/version.rb
54
+ homepage: http://rubygems.org/gems/jenkins-centaur
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '2.1'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.2.0
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Start jenkins jobs from a configuration
78
+ test_files: []