jenkins-cli 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +6 -0
- data/README +29 -0
- data/Rakefile +15 -0
- data/TODO +20 -0
- data/bin/jenkins-cli +87 -0
- data/jenkins-cli.gemspec +22 -0
- data/lib/add_executor.rb +38 -0
- data/lib/build_details.rb +26 -0
- data/lib/build_history.rb +26 -0
- data/lib/disable_emails.rb +28 -0
- data/lib/display_queue.rb +22 -0
- data/lib/enable_emails.rb +31 -0
- data/lib/grant_user.rb +23 -0
- data/lib/groovy/add_slave.groovy +65 -0
- data/lib/groovy/build_details.groovy +53 -0
- data/lib/groovy/build_history.groovy +29 -0
- data/lib/groovy/disable_email.groovy +27 -0
- data/lib/groovy/display_queue.groovy +29 -0
- data/lib/groovy/email_details.groovy +36 -0
- data/lib/groovy/enable_email.groovy +72 -0
- data/lib/groovy/grant_user.groovy +4 -0
- data/lib/groovy/job_details.groovy +57 -0
- data/lib/groovy/list_failing_jobs.groovy +20 -0
- data/lib/groovy/list_nodes.groovy +12 -0
- data/lib/groovy/modify_labels.groovy +24 -0
- data/lib/groovy/nodes.groovy +10 -0
- data/lib/groovy/stream_log.groovy +33 -0
- data/lib/jenkins-cli.jar +0 -0
- data/lib/jenkins-cli/version.rb +3 -0
- data/lib/jenkins_controller.rb +110 -0
- data/lib/job_details.rb +25 -0
- data/lib/job_labels.rb +27 -0
- data/lib/list_failing_jobs.rb +25 -0
- data/lib/list_jobs.rb +25 -0
- data/lib/start_job.rb +28 -0
- data/lib/stream_log.rb +25 -0
- metadata +100 -0
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
What does jenkins-cli do?
|
2
|
+
==================================
|
3
|
+
|
4
|
+
1. Allows you to modify Jenkins slave configurations
|
5
|
+
2. Allows you to disable/enable emails if you're using the Ext-email plugin
|
6
|
+
3. Start a build
|
7
|
+
4. Lists all failing jobs
|
8
|
+
5. Retrieve details pertaining to a Jenkins job (e.g. current build status, last successful, last failed, etc.)
|
9
|
+
6. Ability to query for what is current building and pending
|
10
|
+
7. Ability to modify Jenkins job labels
|
11
|
+
8. Can retrieve the build history of a Jenkins job
|
12
|
+
9. Retrieve details of a particular build (e.g. committers, SCM changes, etc.)
|
13
|
+
10. Ability to stream logs of a currently building job.
|
14
|
+
|
15
|
+
How to install jenkins-cli
|
16
|
+
==================================
|
17
|
+
|
18
|
+
Install jenkins-cli into your gemset
|
19
|
+
gem install jenkins-cli
|
20
|
+
|
21
|
+
Optionally set $JENKINS_URL to your Jenkins master machine.
|
22
|
+
Optionally set $JENKINS_USER to your Jenkins username you wish to operate as.
|
23
|
+
|
24
|
+
How to use jenkins-cli
|
25
|
+
=================================
|
26
|
+
|
27
|
+
Usage: jenkins-cli <command> [OPTIONS]
|
28
|
+
|
29
|
+
For a list of available commands just use type 'jenkins-cli'
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
load "#{ENV['REPO_ROOT']}/ooyala/shared_lib/ooyala_gems/ooyala_gems.rake"
|
5
|
+
|
6
|
+
namespace :jenkins_cli do
|
7
|
+
desc "Push latest jenkins-cli gem to gems.sv2"
|
8
|
+
task :push_gem do
|
9
|
+
gem_to_push = nil
|
10
|
+
Dir.glob('jenkins-cli*.gem').each do |f|
|
11
|
+
gem_to_push = f
|
12
|
+
end
|
13
|
+
puts `rake gem:push #{gem_to_push}` if gem_to_push
|
14
|
+
end
|
15
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
[x] Ability to modify slaves
|
2
|
+
[x] Ability to disable/enable emails
|
3
|
+
[x] Ability to set emails addresses
|
4
|
+
[x] Ability to start the build for any task
|
5
|
+
[x] Ability to list all failing jobs
|
6
|
+
[x] Ability to retrieve details of a job (i.e. lastSuccessfulBuild, lastFailingBuild, currentStatus)
|
7
|
+
[x] Ability to query queue and what is building
|
8
|
+
[x] Ability to modify labels
|
9
|
+
[x] Default to JENKINS_USER if it exists
|
10
|
+
[] Grant users access to Jenkins
|
11
|
+
[x] Stream the logs to the current console
|
12
|
+
[] Output log to a file
|
13
|
+
[x] Get build history for a job
|
14
|
+
[x] Get build details
|
15
|
+
Ability to query for machines with certain labels
|
16
|
+
Ability to add a label to multiple machines
|
17
|
+
Ability to add a label to multiple jobs
|
18
|
+
|
19
|
+
|
20
|
+
|
data/bin/jenkins-cli
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
require "#{File.dirname(__FILE__)}/../lib/jenkins_controller"
|
5
|
+
|
6
|
+
DEFAULT_SSH_USER = "role-c3"
|
7
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
8
|
+
|
9
|
+
usage = <<-EOF
|
10
|
+
Usage:
|
11
|
+
jenkins-cli <command> [OPTIONS]
|
12
|
+
Examples:
|
13
|
+
jenkins-cli list-failures
|
14
|
+
jenkins-cli disable-email --jenkins-url http://localhost:8080 --user jenkins --projects "sas-coverage rails-coverage"
|
15
|
+
Supported Commands:
|
16
|
+
add-node [jenkins-url | user | name | ssh_user | mode | slave-url | v]
|
17
|
+
build-details [jenkins-url | user | job | build-number]
|
18
|
+
build-history [jenkins-url | user | job | limit]
|
19
|
+
disable-email [jenkins-url | user | projects]
|
20
|
+
enable-email [jenkins-url | user | projects | emails]
|
21
|
+
grant-access [jenkins-url | user | grant-user]
|
22
|
+
job-details [jenkins-url | user | job]
|
23
|
+
job-labels [jenkins-url | user | job | labels]
|
24
|
+
list-failures [jenkins-url | user]
|
25
|
+
list-jobs [jenkins-url | user]
|
26
|
+
log [jenkins-url | user | job]
|
27
|
+
queue [jenkins-url | user]
|
28
|
+
start-job [jenkins-url | user | job]
|
29
|
+
EOF
|
30
|
+
|
31
|
+
opts = Trollop::options do
|
32
|
+
banner usage
|
33
|
+
opt :name, "Slave name", :default => nil, :type => String, :short => "-n"
|
34
|
+
opt :user, "Jenkins username", :default => nil, :type => String, :short => "-u"
|
35
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
36
|
+
opt :ssh_user, "SSH username", :default => DEFAULT_SSH_USER
|
37
|
+
opt :jenkins_url, "Jenkins main URL", :default => nil, :type => String
|
38
|
+
opt :mode, "Jenkins slave mode", :default => "exclusive"
|
39
|
+
opt :slave_url, "Slave URL", :default => nil, :type => String
|
40
|
+
opt :verbose, "Verbose", :default => false, :short => "-v"
|
41
|
+
opt :projects, "Jenkins projects to disable emails from.", :default => nil, :type => String, :short => "-p"
|
42
|
+
opt :emails, "List of recipients to receive email.", :default => "", :type => String, :short => "-e"
|
43
|
+
opt :job, "Jenkins job", :default => nil, :type => String, :short => "-j"
|
44
|
+
opt :labels, "Jenkins label expression", :default => nil, :type => String
|
45
|
+
opt :grant_user, "Jenkins user to grant write permissions to.", :default => nil, :type => String
|
46
|
+
opt :build_number, "Build number of a particular Jenkins job.", :default => nil, :type => String, :short => "-b"
|
47
|
+
opt :limit, "The number of entries to show", :default => nil, :type => String, :short => "-l"
|
48
|
+
end
|
49
|
+
|
50
|
+
# If jenkins_url is not set then set it to JENKINS_URL env var if it exists
|
51
|
+
opts[:jenkins_url] = ENV['JENKINS_URL'] if opts[:jenkins_url].nil?
|
52
|
+
opts[:user] = ENV['JENKINS_USER'] if opts[:user].nil?
|
53
|
+
opts[:password] = ENV['JENKINS_PASSWORD'] if opts[:password].nil?
|
54
|
+
|
55
|
+
# Otherwise set it to DEFAULT_JENKINS_URL
|
56
|
+
opts[:jenkins_url] = DEFAULT_JENKINS_URL if opts[:jenkins_url].nil?
|
57
|
+
|
58
|
+
if ARGV[0] && ARGV[0] == "list-jobs"
|
59
|
+
JenkinsController.list_jobs(opts[:jenkins_url], opts[:user], opts[:password])
|
60
|
+
elsif ARGV[0] && ARGV[0] == "disable-email"
|
61
|
+
JenkinsController.disable_email(opts[:jenkins_url], opts[:user], opts[:password], opts[:projects])
|
62
|
+
elsif ARGV[0] && ARGV[0] == "enable-email"
|
63
|
+
JenkinsController.enable_email(opts[:jenkins_url], opts[:user], opts[:password], opts[:projects], opts[:emails])
|
64
|
+
elsif ARGV[0] && ARGV[0] == "add-node"
|
65
|
+
JenkinsController.add_node(opts[:jenkins_url], opts[:user], opts[:password], opts[:name], opts[:ssh_user], opts[:mode], opts[:slave_url], opts[:v])
|
66
|
+
elsif ARGV[0] && ARGV[0] == "start-job"
|
67
|
+
JenkinsController.start_job(opts[:jenkins_url], opts[:user], opts[:password], opts[:job])
|
68
|
+
elsif ARGV[0] && ARGV[0] == "list-failures"
|
69
|
+
JenkinsController.list_failures(opts[:jenkins_url], opts[:user], opts[:password])
|
70
|
+
elsif ARGV[0] && ARGV[0] == "job-details"
|
71
|
+
JenkinsController.job_details(opts[:jenkins_url], opts[:user], opts[:password], opts[:job])
|
72
|
+
elsif ARGV[0] && ARGV[0] == "queue"
|
73
|
+
JenkinsController.queue(opts[:jenkins_url], opts[:user], opts[:password])
|
74
|
+
elsif ARGV[0] && ARGV[0] == "job-labels"
|
75
|
+
JenkinsController.job_labels(opts[:jenkins_url], opts[:user], opts[:password], opts[:job], opts[:labels])
|
76
|
+
elsif ARGV[0] && ARGV[0] == "grant-access"
|
77
|
+
JenkinsController.grant_access(opts[:jenkins_url], opts[:user], opts[:password], opts[:grant_user])
|
78
|
+
elsif ARGV[0] && ARGV[0] == "log"
|
79
|
+
JenkinsController.log(opts[:jenkins_url], opts[:user], opts[:password], opts[:job])
|
80
|
+
elsif ARGV[0] && ARGV[0] == "build-history"
|
81
|
+
JenkinsController.build_history(opts[:jenkins_url], opts[:user], opts[:password], opts[:job], opts[:limit])
|
82
|
+
elsif ARGV[0] && ARGV[0] == "build-details"
|
83
|
+
JenkinsController.build_details(opts[:jenkins_url], opts[:user], opts[:password], opts[:job], opts[:build_number])
|
84
|
+
else
|
85
|
+
puts usage
|
86
|
+
exit(1)
|
87
|
+
end
|
data/jenkins-cli.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "jenkins-cli/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "jenkins-cli"
|
7
|
+
s.version = JenkinsCLI::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Viet Nguyen"]
|
10
|
+
s.email = ["viet@ooyala.com"]
|
11
|
+
s.homepage = "http://www.ooyala.com"
|
12
|
+
s.summary = "This jenkins-cli gem is an internal tool to Ooyala for managing a Jenkins instance from the command"
|
13
|
+
s.description = "Jenkins gem"
|
14
|
+
|
15
|
+
s.rubyforge_project = "jenkins-cli"
|
16
|
+
|
17
|
+
s.add_dependency("trollop")
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
end
|
data/lib/add_executor.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_SSH_USER = "role-c3"
|
6
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
7
|
+
|
8
|
+
OPTIONS = Trollop::options do
|
9
|
+
opt :name, "Slave name", :default => nil, :type => String
|
10
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
11
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
12
|
+
opt :ssh_user, "SSH username", :default => DEFAULT_SSH_USER
|
13
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
14
|
+
opt :mode, "Jenkins slave mode", :default => "exclusive"
|
15
|
+
opt :slave_url, "Slave URL", :default => nil, :type => String
|
16
|
+
opt :v, "Verbose", :default => false
|
17
|
+
end
|
18
|
+
|
19
|
+
p OPTIONS
|
20
|
+
|
21
|
+
Trollop::die :slave_url, "Must be set with a protocol" if OPTIONS[:slave_url].nil?
|
22
|
+
Trollop::die :name, "Must be set" if OPTIONS[:name].nil?
|
23
|
+
Trollop::die :mode, "Must be either exclusive or normal" unless ["exclusive", "normal"].include?(OPTIONS[:mode])
|
24
|
+
|
25
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
26
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
27
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
28
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
29
|
+
|
30
|
+
groovy_params = "#{OPTIONS[:name]} #{OPTIONS[:mode]} #{OPTIONS[:slave_url]} #{OPTIONS[:ssh_user]}"
|
31
|
+
|
32
|
+
base_dir = File.dirname(__FILE__)
|
33
|
+
|
34
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/add_slave.groovy #{groovy_params}"
|
35
|
+
|
36
|
+
puts "Command: #{cmd}" if OPTIONS[:v]
|
37
|
+
system( cmd )
|
38
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
OPTIONS = Trollop::options do
|
8
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
9
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
10
|
+
opt :password, "Jenkins password", :default => nil, :type => St
|
11
|
+
opt :job, "Jenkins job to view the detail of", :default => nil, :type => String
|
12
|
+
opt :build_number, "Build number of a particular Jenkins job.", :default => nil, :type => String
|
13
|
+
end
|
14
|
+
|
15
|
+
Trollop::die :job, "Must specify a Jenkins job to view the details" if OPTIONS[:job].nil?
|
16
|
+
|
17
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
18
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
19
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
20
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
21
|
+
|
22
|
+
base_dir = File.dirname(__FILE__)
|
23
|
+
|
24
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/build_details.groovy #{OPTIONS[:job]} #{OPTIONS[:build_number]}"
|
25
|
+
|
26
|
+
system( cmd )
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
OPTIONS = Trollop::options do
|
8
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
9
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
10
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
11
|
+
opt :job, "Jenkins job to view the detail of", :default => nil, :type => String
|
12
|
+
opt :limit, "The number of builds in the history to show.", :default => nil, :type => String
|
13
|
+
end
|
14
|
+
|
15
|
+
Trollop::die :job, "Must specify a Jenkins job to view the details" if OPTIONS[:job].nil?
|
16
|
+
|
17
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
18
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
19
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
20
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
21
|
+
|
22
|
+
base_dir = File.dirname(__FILE__)
|
23
|
+
|
24
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/build_history.groovy #{OPTIONS[:job]} #{OPTIONS[:limit]}"
|
25
|
+
|
26
|
+
system( cmd )
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
OPTIONS = Trollop::options do
|
8
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
9
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
10
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
11
|
+
opt :projects, "Jenkins projects to disable emails from.", :default => nil, :type => String
|
12
|
+
end
|
13
|
+
|
14
|
+
Trollop::die :projects, "Must be a space delimited list of Jenkins projects" if OPTIONS[:projects].nil?
|
15
|
+
|
16
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
17
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
18
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
19
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
20
|
+
|
21
|
+
base_dir = File.dirname(__FILE__)
|
22
|
+
|
23
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/disable_email.groovy #{OPTIONS[:projects]}"
|
24
|
+
|
25
|
+
system( cmd )
|
26
|
+
|
27
|
+
|
28
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
OPTIONS = Trollop::options do
|
8
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
9
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
10
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
11
|
+
end
|
12
|
+
|
13
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
14
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
15
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
16
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
17
|
+
|
18
|
+
base_dir = File.dirname(__FILE__)
|
19
|
+
|
20
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/display_queue.groovy"
|
21
|
+
|
22
|
+
system( cmd )
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
OPTIONS = Trollop::options do
|
8
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
9
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
10
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
11
|
+
opt :projects, "Jenkins projects to disable emails from.", :default => nil, :type => String
|
12
|
+
opt :emails, "List of recipients to receive email.", :default => "", :type => String
|
13
|
+
end
|
14
|
+
|
15
|
+
Trollop::die :projects, "Must be a space delimited list of Jenkins projects" if OPTIONS[:projects].nil?
|
16
|
+
|
17
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
18
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
19
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
20
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
21
|
+
|
22
|
+
base_dir = File.dirname(__FILE__)
|
23
|
+
|
24
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/enable_email.groovy '#{OPTIONS[:projects]}' '#{OPTIONS[:emails]}'"
|
25
|
+
|
26
|
+
puts cmd
|
27
|
+
|
28
|
+
system( cmd )
|
29
|
+
|
30
|
+
|
31
|
+
|
data/lib/grant_user.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
OPTIONS = Trollop::options do
|
8
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
9
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
10
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
11
|
+
opt :grant_user, "Jenkins user to grant permissions to.", :default => nil, :type => String
|
12
|
+
end
|
13
|
+
|
14
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
15
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
16
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
17
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
18
|
+
|
19
|
+
base_dir = File.dirname(__FILE__)
|
20
|
+
|
21
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/grant_user.groovy #{OPTIONS[:grant_user]}"
|
22
|
+
|
23
|
+
system( cmd )
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import hudson.model.*
|
2
|
+
import hudson.slaves.*
|
3
|
+
import hudson.plugins.sshslaves.SSHLauncher
|
4
|
+
|
5
|
+
if(this.args.length != 4) {
|
6
|
+
println("Usage: add_slave.groovy <slave_name> <exclusive/normal> <slave_url> <user>")
|
7
|
+
return
|
8
|
+
}
|
9
|
+
|
10
|
+
def slave_name = this.args[0]
|
11
|
+
def mode = this.args[1].equals("exclusive") ? Node.Mode.EXCLUSIVE : Node.Mode.NORMAL
|
12
|
+
def slave_url = this.args[2]
|
13
|
+
def user = this.args[3]
|
14
|
+
|
15
|
+
jenkins = jenkins.model.Jenkins.instance
|
16
|
+
|
17
|
+
def slaveExists = false
|
18
|
+
def slaves = jenkins.getNodes()
|
19
|
+
def currSlave = null
|
20
|
+
slaves.each {
|
21
|
+
slave ->
|
22
|
+
if(slave.getNodeName().equals( slave_name )) {
|
23
|
+
slaveExists = true
|
24
|
+
currSlave = slave
|
25
|
+
jenkins.removeNode(slave)
|
26
|
+
return
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
println("Attempting to modify/add Jenkins node: " + slave_name )
|
31
|
+
println(" + Slave URL: " + slave_url)
|
32
|
+
println(" + Slave Name: " + slave_name)
|
33
|
+
println(" + Mode: " + mode)
|
34
|
+
println(" + User: " + user)
|
35
|
+
|
36
|
+
sshLauncher = new SSHLauncher(
|
37
|
+
slave_url,
|
38
|
+
22,
|
39
|
+
user,
|
40
|
+
"",
|
41
|
+
"",
|
42
|
+
"")
|
43
|
+
|
44
|
+
if( !slaveExists ) {
|
45
|
+
// Preparing a new Node to add
|
46
|
+
def node = new DumbSlave(
|
47
|
+
slave_name,
|
48
|
+
"",
|
49
|
+
"/var/lib/jenkins",
|
50
|
+
"1",
|
51
|
+
mode,
|
52
|
+
"",
|
53
|
+
sshLauncher,
|
54
|
+
RetentionStrategy.Always.INSTANCE,
|
55
|
+
new ArrayList<NodeProperty>())
|
56
|
+
|
57
|
+
jenkins.addNode( node )
|
58
|
+
} else {
|
59
|
+
// Modifying an existing Node
|
60
|
+
currSlave.setLauncher( sshLauncher )
|
61
|
+
currSlave.setMode( mode )
|
62
|
+
currSlave.setNodeName( slave_name )
|
63
|
+
// TODO
|
64
|
+
jenkins.addNode( currSlave )
|
65
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
jenkins = jenkins.model.Jenkins.instance
|
2
|
+
|
3
|
+
if(this.args.length != 2) {
|
4
|
+
println("build_details.groovy needs 1 parameter (i.e. job, build number)")
|
5
|
+
return
|
6
|
+
}
|
7
|
+
|
8
|
+
jobName = this.args[0]
|
9
|
+
buildNumber = Integer.parseInt(this.args[1])
|
10
|
+
|
11
|
+
println(jobName + " #" + buildNumber)
|
12
|
+
|
13
|
+
jenkins.items.each {
|
14
|
+
job ->
|
15
|
+
if( job.isBuildable() && job.name.equals( jobName ) ) {
|
16
|
+
def build = job.getBuildByNumber( buildNumber )
|
17
|
+
// Start date
|
18
|
+
println(" Built " + build.getTimestampString() + " ago")
|
19
|
+
// Duration
|
20
|
+
println(" Duration: " + build.getDurationString())
|
21
|
+
// Committers
|
22
|
+
println(" Potential Culprits:")
|
23
|
+
def culprits = build.getCulprits()
|
24
|
+
for(String c : culprits) {
|
25
|
+
println(" + " + c)
|
26
|
+
}
|
27
|
+
// SCM changes
|
28
|
+
println(" Changeset: ")
|
29
|
+
def changeSet = build.getChangeSet()
|
30
|
+
def items = changeSet.getItems()
|
31
|
+
for(int i = 0 ; i < items.length; i++) {
|
32
|
+
gitChangeSet = items[i]
|
33
|
+
author = gitChangeSet.getAuthorName()
|
34
|
+
comment = gitChangeSet.getComment().replaceAll("\\n", " ")
|
35
|
+
rev = gitChangeSet.getRevision()
|
36
|
+
paths = gitChangeSet.getPaths()
|
37
|
+
println(" " + (i+1) + ". " + comment)
|
38
|
+
println(" Commit: " + rev + " by (" + author + ")")
|
39
|
+
for(hudson.plugins.git.GitChangeSet.Path path : paths) {
|
40
|
+
editType = path.getEditType()
|
41
|
+
if(editType == hudson.scm.EditType.ADD) {
|
42
|
+
println(" + " + path.getPath())
|
43
|
+
} else if(editType == hudson.scm.EditType.DELETE) {
|
44
|
+
println(" - " + path.getPath())
|
45
|
+
} else if(editType == hudson.scm.EditType.EDIT) {
|
46
|
+
println(" E " + path.getPath())
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
return
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
jenkins = jenkins.model.Jenkins.instance
|
2
|
+
|
3
|
+
if(this.args.length < 1) {
|
4
|
+
println("build_history.groovy needs at least 1 parameter (i.e. job, optional is limit)")
|
5
|
+
return
|
6
|
+
}
|
7
|
+
|
8
|
+
jobName = this.args[0]
|
9
|
+
numRunsToShow = 10
|
10
|
+
if(this.args.length == 2) {
|
11
|
+
numRunsToShow = Integer.parseInt(this.args[1])
|
12
|
+
}
|
13
|
+
|
14
|
+
println(jobName)
|
15
|
+
|
16
|
+
jenkins.items.each {
|
17
|
+
job ->
|
18
|
+
if( job.isBuildable() && job.name.equals( jobName ) ) {
|
19
|
+
def builds = job.getBuildsAsMap().values()
|
20
|
+
int i = 0
|
21
|
+
for(hudson.model.Run build : builds) {
|
22
|
+
println(" + " + build.number + " => " + build.getResult())
|
23
|
+
i++
|
24
|
+
if(i == numRunsToShow) {
|
25
|
+
break
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
jenkins = jenkins.model.Jenkins.instance
|
2
|
+
|
3
|
+
allItems = jenkins.items
|
4
|
+
|
5
|
+
def toRemove = new HashSet()
|
6
|
+
|
7
|
+
for(int i = 0 ; i < this.args.length; i++) {
|
8
|
+
toRemove.add(this.args[i].toLowerCase())
|
9
|
+
}
|
10
|
+
|
11
|
+
allItems.each {
|
12
|
+
run ->
|
13
|
+
list = run.getPublishersList()
|
14
|
+
list.each {
|
15
|
+
publisher ->
|
16
|
+
if(publisher.class == hudson.plugins.emailext.ExtendedEmailPublisher) {
|
17
|
+
if(toRemove.contains(run.name.toLowerCase())) {
|
18
|
+
println("Disabled email for " + run.name)
|
19
|
+
list.remove(publisher)
|
20
|
+
return
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
jenkins = jenkins.model.Jenkins.instance
|
2
|
+
|
3
|
+
def jobs = jenkins.items
|
4
|
+
|
5
|
+
def building = new ArrayList()
|
6
|
+
def queued = new ArrayList()
|
7
|
+
|
8
|
+
def queue = jenkins.getQueue()
|
9
|
+
def itemsInQueue = queue.getItems()
|
10
|
+
|
11
|
+
for(int i = 0 ; i < jobs.size() ; i++) {
|
12
|
+
if(jobs[i].isBuildable() && jobs[i].isBuilding()) {
|
13
|
+
building.add(jobs[i].name)
|
14
|
+
} else if(jobs[i].isBuildable() && jobs[i].isInQueue()) {
|
15
|
+
queued.add(jobs[i].name)
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
println("Items currently building:")
|
20
|
+
for(int i = 0 ; i < building.size(); i++) {
|
21
|
+
println(" + " + building[i])
|
22
|
+
}
|
23
|
+
println()
|
24
|
+
println("Items in the build queue:")
|
25
|
+
for(int i = itemsInQueue.length - 1 ; i >= 0; i--) {
|
26
|
+
println(" + " + itemsInQueue[i].task.getName())
|
27
|
+
}
|
28
|
+
|
29
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import hudson.plugins.emailext.*
|
2
|
+
|
3
|
+
jenkins = jenkins.model.Jenkins.instance
|
4
|
+
|
5
|
+
allItems = jenkins.items
|
6
|
+
|
7
|
+
allItems.each {
|
8
|
+
run ->
|
9
|
+
list = run.getPublishersList()
|
10
|
+
list.each {
|
11
|
+
publisher ->
|
12
|
+
if(publisher.class == hudson.plugins.emailext.ExtendedEmailPublisher) {
|
13
|
+
println(publisher)
|
14
|
+
|
15
|
+
emailType = new hudson.plugins.emailext.EmailType()
|
16
|
+
emailType.setSendToDevelopers(true)
|
17
|
+
emailType.setSendToRecipientList(true)
|
18
|
+
|
19
|
+
unstableTrigger = new hudson.plugins.emailext.plugins.trigger.UnstableTrigger()
|
20
|
+
unstableTrigger.setEmail(emailType)
|
21
|
+
|
22
|
+
publisher.getConfiguredTriggers().add( unstableTrigger )
|
23
|
+
|
24
|
+
triggers = publisher.getConfiguredTriggers()
|
25
|
+
triggers.each {
|
26
|
+
trigger ->
|
27
|
+
email = trigger.getEmail()
|
28
|
+
println("Send to Developers: " + email.getSendToDevelopers())
|
29
|
+
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import hudson.plugins.emailext.*
|
2
|
+
|
3
|
+
jenkins = jenkins.model.Jenkins.instance
|
4
|
+
|
5
|
+
allItems = jenkins.items
|
6
|
+
|
7
|
+
if(this.args.length != 2) {
|
8
|
+
println("enable_email.groovy requires exactly 2 paramters: <projects> <emails>")
|
9
|
+
return
|
10
|
+
}
|
11
|
+
|
12
|
+
def projects = this.args[0].split(" ")
|
13
|
+
def emails = this.args[1]
|
14
|
+
def toAdd = new HashSet()
|
15
|
+
|
16
|
+
for(int i = 0 ; i < projects.length ; i++) {
|
17
|
+
toAdd.add(projects[i].toLowerCase())
|
18
|
+
}
|
19
|
+
|
20
|
+
allItems.each {
|
21
|
+
run ->
|
22
|
+
if(toAdd.contains(run.name.toLowerCase())) {
|
23
|
+
def alreadyEnabled = false
|
24
|
+
list = run.getPublishersList()
|
25
|
+
list.each {
|
26
|
+
publisher ->
|
27
|
+
if(publisher.class == hudson.plugins.emailext.ExtendedEmailPublisher) {
|
28
|
+
publisher.recipientList = emails
|
29
|
+
alreadyEnabled = true
|
30
|
+
println(run.name.toLowerCase() + " was updated with new email recipients.")
|
31
|
+
}
|
32
|
+
}
|
33
|
+
if( !alreadyEnabled ) {
|
34
|
+
// Set up the email publisher
|
35
|
+
emailPublisher = new hudson.plugins.emailext.ExtendedEmailPublisher()
|
36
|
+
emailPublisher.defaultSubject = '$DEFAULT_SUBJECT'
|
37
|
+
emailPublisher.defaultContent = '$DEFAULT_CONTENT'
|
38
|
+
emailPublisher.recipientList = emails
|
39
|
+
|
40
|
+
triggers = emailPublisher.getEmailTriggers().clear()
|
41
|
+
emailType = new hudson.plugins.emailext.EmailType()
|
42
|
+
emailType.setSendToDevelopers(true)
|
43
|
+
emailType.setSendToRecipientList(true)
|
44
|
+
emailType.setSubject(hudson.plugins.emailext.ExtendedEmailPublisher.PROJECT_DEFAULT_SUBJECT_TEXT)
|
45
|
+
emailType.setBody(hudson.plugins.emailext.ExtendedEmailPublisher.PROJECT_DEFAULT_BODY_TEXT)
|
46
|
+
|
47
|
+
failureTrigger = new hudson.plugins.emailext.plugins.trigger.FailureTrigger()
|
48
|
+
failureTrigger.setEmail(emailType)
|
49
|
+
|
50
|
+
unstableTrigger = new hudson.plugins.emailext.plugins.trigger.UnstableTrigger()
|
51
|
+
unstableTrigger.setEmail(emailType)
|
52
|
+
|
53
|
+
fixedTrigger = new hudson.plugins.emailext.plugins.trigger.FixedTrigger()
|
54
|
+
fixedTrigger.setEmail(emailType)
|
55
|
+
|
56
|
+
emailPublisher.addEmailTriggerType( failureTrigger.getDescriptor() )
|
57
|
+
emailPublisher.addEmailTriggerType( unstableTrigger.getDescriptor() )
|
58
|
+
emailPublisher.addEmailTriggerType( fixedTrigger.getDescriptor() )
|
59
|
+
emailPublisher.getConfiguredTriggers().add( failureTrigger )
|
60
|
+
emailPublisher.getConfiguredTriggers().add( unstableTrigger )
|
61
|
+
emailPublisher.getConfiguredTriggers().add( fixedTrigger )
|
62
|
+
|
63
|
+
// Add the email publisher
|
64
|
+
list.add(emailPublisher)
|
65
|
+
|
66
|
+
println("Enabled emails for " + run.name.toLowerCase())
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
jenkins = jenkins.model.Jenkins.instance
|
2
|
+
|
3
|
+
if(this.args.length != 1) {
|
4
|
+
println("job_details.groovy needs exactly 1 parameter (i.e. job)")
|
5
|
+
return
|
6
|
+
}
|
7
|
+
|
8
|
+
targetJobName = this.args[0]
|
9
|
+
|
10
|
+
allItems = jenkins.items
|
11
|
+
activeJobs = allItems.each {
|
12
|
+
job ->
|
13
|
+
if(job.isBuildable() && job.name.equals( targetJobName )) {
|
14
|
+
def isQueued = job.isInQueue()
|
15
|
+
def isBuilding = job.isBuilding()
|
16
|
+
def status = "UNKNOWN"
|
17
|
+
if( !isQueued && !isBuilding && job.lastBuild != null) {
|
18
|
+
status = job.lastBuild.result
|
19
|
+
} else if( isQueued ) {
|
20
|
+
status = "Queued"
|
21
|
+
} else if( isBuilding ) {
|
22
|
+
status = "In Progress"
|
23
|
+
}
|
24
|
+
|
25
|
+
def lastSuccess = "N/A"
|
26
|
+
now = System.currentTimeMillis()
|
27
|
+
if(job.lastSuccessfulBuild != null) {
|
28
|
+
jobStartTime = job.lastSuccessfulBuild.timestamp.time.getTime()
|
29
|
+
lastSuccess = (now - jobStartTime) / 1000 / 60 // time difference in minutes
|
30
|
+
}
|
31
|
+
|
32
|
+
def lastFailed = "N/A"
|
33
|
+
if(job.lastFailedBuild != null) {
|
34
|
+
jobStartTime = job.lastFailedBuild.timestamp.time.getTime()
|
35
|
+
lastFailed = (now - jobStartTime) / 1000 / 60 // time difference in minutes
|
36
|
+
}
|
37
|
+
|
38
|
+
def recipients = ""
|
39
|
+
publisherList = job.getPublishersList()
|
40
|
+
publisherList.each {
|
41
|
+
publisher ->
|
42
|
+
if(publisher.class == hudson.plugins.emailext.ExtendedEmailPublisher) {
|
43
|
+
recipients = publisher.recipientList
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
println("Job -> " + job.name)
|
48
|
+
println(" Status: " + status)
|
49
|
+
println(" Last Successful Build: " + (int)lastSuccess + " minutes ago")
|
50
|
+
println(" Last Failed Build: " + (int)lastFailed + " minutes ago")
|
51
|
+
println(" Label Expression: " + job.getAssignedLabelString())
|
52
|
+
println(" Email Recipients: " + recipients)
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
jenkins = jenkins.model.Jenkins.instance
|
2
|
+
|
3
|
+
allItems = jenkins.items
|
4
|
+
activeJobs = allItems.findAll {
|
5
|
+
job ->
|
6
|
+
job.isBuildable()
|
7
|
+
}
|
8
|
+
|
9
|
+
failedRuns = activeJobs.findAll {
|
10
|
+
job ->
|
11
|
+
job.lastBuild != null && (job.lastBuild.result == hudson.model.Result.FAILURE || job.lastBuild.result == hudson.model.Result.UNSTABLE)
|
12
|
+
}
|
13
|
+
|
14
|
+
println("\nJobs:")
|
15
|
+
failedRuns.each {
|
16
|
+
run ->
|
17
|
+
println(" + " + run.name)
|
18
|
+
}
|
19
|
+
|
20
|
+
println("\n" + failedRuns.size + " failed Jenkins jobs")
|
@@ -0,0 +1,24 @@
|
|
1
|
+
jenkins = jenkins.model.Jenkins.instance
|
2
|
+
|
3
|
+
if(this.args.length != 2) {
|
4
|
+
println("modify_labels.groovy needs exactly 2 parameter (i.e. <job> <label_string>)")
|
5
|
+
return
|
6
|
+
}
|
7
|
+
|
8
|
+
targetJobName = this.args[0]
|
9
|
+
labelStr = this.args[1]
|
10
|
+
|
11
|
+
allItems = jenkins.items
|
12
|
+
activeJobs = allItems.each {
|
13
|
+
job ->
|
14
|
+
if(job.isBuildable() && job.name.equals( targetJobName )) {
|
15
|
+
def labelAtom = new hudson.model.labels.LabelAtom(labelStr)
|
16
|
+
job.setAssignedLabel( labelAtom )
|
17
|
+
println("Raw Input: " + labelStr)
|
18
|
+
println("Input: " + labelAtom.getExpression())
|
19
|
+
println("Assigned label string is " + job.getAssignedLabelString())
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
jenkins = jenkins.model.Jenkins.instance
|
2
|
+
|
3
|
+
allItems = jenkins.items
|
4
|
+
|
5
|
+
if(this.args.length != 1) {
|
6
|
+
println("job_details.groovy needs exactly 1 parameter (i.e. job)")
|
7
|
+
return
|
8
|
+
}
|
9
|
+
|
10
|
+
targetJobName = this.args[0]
|
11
|
+
|
12
|
+
allItems.each {
|
13
|
+
job ->
|
14
|
+
if(job.isBuildable() && job.name.equals( targetJobName )) {
|
15
|
+
inputStream = job.getLastBuild().getLogInputStream()
|
16
|
+
println(inputStream)
|
17
|
+
def c = ' '
|
18
|
+
def firstTime = true
|
19
|
+
while( firstTime || job.isBuilding() ) {
|
20
|
+
firstTime = false
|
21
|
+
while( (c = inputStream.read()) != -1 ) {
|
22
|
+
print((char)c)
|
23
|
+
}
|
24
|
+
Thread.sleep(1000)
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
println()
|
30
|
+
println("*** END OF LOG ***")
|
31
|
+
|
32
|
+
|
33
|
+
|
data/lib/jenkins-cli.jar
ADDED
Binary file
|
@@ -0,0 +1,110 @@
|
|
1
|
+
class JenkinsController
|
2
|
+
def self.build_history(jenkins_url, user, password, job, limit)
|
3
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
4
|
+
user = "--user #{user}" unless user.nil?
|
5
|
+
password = "--password #{password}" unless password.nil?
|
6
|
+
job = "--job #{job}" unless job.nil?
|
7
|
+
limit = "--limit #{limit}" unless limit.nil?
|
8
|
+
system "#{File.dirname(__FILE__)}/build_history.rb #{jenkins_url} #{user} #{password} #{job} #{limit}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.build_details(jenkins_url, user, password, job, num)
|
12
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
13
|
+
user = "--user #{user}" unless user.nil?
|
14
|
+
password = "--password #{password}" unless password.nil?
|
15
|
+
job = "--job #{job}" unless job.nil?
|
16
|
+
build_number = "--build-number #{num}" unless num.nil?
|
17
|
+
system "#{File.dirname(__FILE__)}/build_details.rb #{jenkins_url} #{user} #{password} #{job} #{build_number}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.log(jenkins_url, user, password, job)
|
21
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
22
|
+
user = "--user #{user}" unless user.nil?
|
23
|
+
password = "--password #{password}" unless password.nil?
|
24
|
+
job = "--job #{job}" unless job.nil?
|
25
|
+
system "#{File.dirname(__FILE__)}/stream_log.rb #{jenkins_url} #{user} #{password} #{job}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.grant_access(jenkins_url, user, password, grant_user)
|
29
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
30
|
+
user = "--user #{user}" unless user.nil?
|
31
|
+
password = "--password #{password}" unless password.nil?
|
32
|
+
grant_user = "--grant-user #{grant_user}" unless grant_user.nil?
|
33
|
+
system "#{File.dirname(__FILE__)}/grant_user.rb #{jenkins_url} #{user} #{password} #{grant_user}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.job_labels(jenkins_url, user, password, job, labels)
|
37
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
38
|
+
user = "--user #{user}" unless user.nil?
|
39
|
+
password = "--password #{password}" unless password.nil?
|
40
|
+
job = "--job #{job}" unless job.nil?
|
41
|
+
labels = "--labels '#{labels}'" unless labels.nil?
|
42
|
+
system "#{File.dirname(__FILE__)}/job_labels.rb #{jenkins_url} #{user} #{password} #{job} #{labels}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.queue(jenkins_url, user, password)
|
46
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
47
|
+
user = "--user #{user}" unless user.nil?
|
48
|
+
password = "--password #{password}" unless password.nil?
|
49
|
+
system "#{File.dirname(__FILE__)}/display_queue.rb #{jenkins_url} #{user} #{password}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.job_details(jenkins_url, user, password, job)
|
53
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
54
|
+
user = "--user #{user}" unless user.nil?
|
55
|
+
password = "--password #{password}" unless password.nil?
|
56
|
+
job = "--job #{job}" unless job.nil?
|
57
|
+
system "#{File.dirname(__FILE__)}/job_details.rb #{jenkins_url} #{user} #{password} #{job}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.list_failures(jenkins_url, user, password)
|
61
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
62
|
+
user = "--user #{user}" unless user.nil?
|
63
|
+
password = "--password #{password}" unless password.nil?
|
64
|
+
system "#{File.dirname(__FILE__)}/list_failing_jobs.rb #{jenkins_url} #{user} #{password}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.start_job(jenkins_url, user, password, job)
|
68
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
69
|
+
user = "--user #{user}" unless user.nil?
|
70
|
+
password = "--password #{password}" unless password.nil?
|
71
|
+
job = "--job #{job}" unless job.nil?
|
72
|
+
system "#{File.dirname(__FILE__)}/start_job.rb #{jenkins_url} #{user} #{password} #{job}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.list_jobs(jenkins_url, user, password)
|
76
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
77
|
+
user = "--user #{user}" unless user.nil?
|
78
|
+
password = "--password #{password}" unless password.nil?
|
79
|
+
system "#{File.dirname(__FILE__)}/list_jobs.rb #{jenkins_url} #{user} #{password}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.disable_email(jenkins_url, user, password, projects)
|
83
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
84
|
+
user = "--user #{user}" unless user.nil?
|
85
|
+
password = "--password #{password}" unless password.nil?
|
86
|
+
projects = "--projects '#{projects}'" unless projects.nil?
|
87
|
+
system "#{File.dirname(__FILE__)}/disable_emails.rb #{jenkins_url} #{user} #{password} #{projects}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.enable_email(jenkins_url, user, password, projects, emails)
|
91
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
92
|
+
user = "--user #{user}" unless user.nil?
|
93
|
+
password = "--password #{password}" unless password.nil?
|
94
|
+
projects = "--projects '#{projects}'" unless projects.nil?
|
95
|
+
emails = "--emails '#{emails}'" unless emails.nil?
|
96
|
+
system "#{File.dirname(__FILE__)}/enable_emails.rb #{jenkins_url} #{user} #{password} #{projects} #{emails}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.add_node(jenkins_url, user, password, name, ssh_user, mode, slave_url, v)
|
100
|
+
jenkins_url = "--jenkins-url #{jenkins_url}" unless jenkins_url.nil?
|
101
|
+
user = "--user #{user}" unless user.nil?
|
102
|
+
password = "--password #{password}" unless password.nil?
|
103
|
+
name = "--name #{name}" unless name.nil?
|
104
|
+
ssh_user = "--ssh-user #{ssh_user}" unless ssh_user.nil?
|
105
|
+
mode = "--mode #{mode}" unless mode.nil?
|
106
|
+
slave_url = "--slave-url #{slave_url}" unless slave_url.nil?
|
107
|
+
v = "--v #{v}" unless v.nil?
|
108
|
+
system "#{File.dirname(__FILE__)}/add_executor.rb #{jenkins_url} #{user} #{password} #{name} #{ssh_user} #{mode} #{slave_url} #{v}"
|
109
|
+
end
|
110
|
+
end
|
data/lib/job_details.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
OPTIONS = Trollop::options do
|
8
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
9
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
10
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
11
|
+
opt :job, "Jenkins job to view the detail of", :default => nil, :type => String
|
12
|
+
end
|
13
|
+
|
14
|
+
Trollop::die :job, "Must specify a Jenkins job to view the details" if OPTIONS[:job].nil?
|
15
|
+
|
16
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
17
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
18
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
19
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
20
|
+
|
21
|
+
base_dir = File.dirname(__FILE__)
|
22
|
+
|
23
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/job_details.groovy #{OPTIONS[:job]}"
|
24
|
+
|
25
|
+
system( cmd )
|
data/lib/job_labels.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
OPTIONS = Trollop::options do
|
8
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
9
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
10
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
11
|
+
opt :job, "Jenkins job to view the detail of", :default => nil, :type => String
|
12
|
+
opt :labels, "A Jenkins label expression", :default => nil, :type => String
|
13
|
+
end
|
14
|
+
|
15
|
+
Trollop::die :job, "Must specify a Jenkins job to view the details" if OPTIONS[:job].nil?
|
16
|
+
Trollop::die :labels, "Must specify a label" if OPTIONS[:labels].nil?
|
17
|
+
|
18
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
19
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
20
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
21
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
22
|
+
|
23
|
+
base_dir = File.dirname(__FILE__)
|
24
|
+
|
25
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/modify_labels.groovy #{OPTIONS[:job]} '#{OPTIONS[:labels]}'"
|
26
|
+
|
27
|
+
system( cmd )
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
# TODO(viet): Add the ability to search jobs with prefixes.
|
8
|
+
# TODO(viet): Add the ability to show more detail of specific jobs (e.g. labels, repos, lastSuccess, jobStatus)
|
9
|
+
|
10
|
+
OPTIONS = Trollop::options do
|
11
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
12
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
13
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
14
|
+
end
|
15
|
+
|
16
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
17
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
18
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
19
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
20
|
+
|
21
|
+
base_dir = File.dirname(__FILE__)
|
22
|
+
|
23
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/list_failing_jobs.groovy"
|
24
|
+
|
25
|
+
system( cmd )
|
data/lib/list_jobs.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
# TODO(viet): Add the ability to search jobs with prefixes.
|
8
|
+
# TODO(viet): Add the ability to show more detail of specific jobs (e.g. labels, repos, lastSuccess, jobStatus)
|
9
|
+
|
10
|
+
OPTIONS = Trollop::options do
|
11
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
12
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
13
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
14
|
+
end
|
15
|
+
|
16
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
17
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
18
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
19
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
20
|
+
|
21
|
+
base_dir = File.dirname(__FILE__)
|
22
|
+
|
23
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/list_nodes.groovy"
|
24
|
+
|
25
|
+
system( cmd )
|
data/lib/start_job.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
# TODO(viet): Add the ability to search jobs with prefixes.
|
8
|
+
# TODO(viet): Add the ability to show more detail of specific jobs (e.g. labels, repos, lastSuccess, jobStatus)
|
9
|
+
|
10
|
+
OPTIONS = Trollop::options do
|
11
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
12
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
13
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
14
|
+
opt :job, "Jenkins job to start", :default => nil, :type => String
|
15
|
+
end
|
16
|
+
|
17
|
+
Trollop::die :job, "Must define a job to start" if OPTIONS[:job].nil?
|
18
|
+
|
19
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
20
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
21
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
22
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
23
|
+
|
24
|
+
base_dir = File.dirname(__FILE__)
|
25
|
+
|
26
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} build #{OPTIONS[:job]} #{jenkins_username} #{jenkins_password}"
|
27
|
+
|
28
|
+
system( cmd )
|
data/lib/stream_log.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
DEFAULT_JENKINS_URL = "http://localhost:8080"
|
6
|
+
|
7
|
+
OPTIONS = Trollop::options do
|
8
|
+
opt :jenkins_url, "Jenkins main URL", :default => DEFAULT_JENKINS_URL
|
9
|
+
opt :user, "Jenkins username", :default => nil, :type => String
|
10
|
+
opt :password, "Jenkins password", :default => nil, :type => String
|
11
|
+
opt :job, "Jenkins job to view the detail of", :default => nil, :type => String
|
12
|
+
end
|
13
|
+
|
14
|
+
Trollop::die :job, "Must specify a Jenkins job to view the details" if OPTIONS[:job].nil?
|
15
|
+
|
16
|
+
jenkins_username = "--username #{OPTIONS[:user]}"
|
17
|
+
jenkins_username = "" if OPTIONS[:user].nil?
|
18
|
+
jenkins_password = "--password #{OPTIONS[:password]}"
|
19
|
+
jenkins_password = "" if OPTIONS[:password].nil?
|
20
|
+
|
21
|
+
base_dir = File.dirname(__FILE__)
|
22
|
+
|
23
|
+
cmd = "java -jar #{base_dir}/jenkins-cli.jar -s #{OPTIONS[:jenkins_url]} groovy #{jenkins_username} #{jenkins_password} #{base_dir}/groovy/stream_log.groovy #{OPTIONS[:job]}"
|
24
|
+
|
25
|
+
system( cmd )
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jenkins-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.3
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Viet Nguyen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-01-01 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: trollop
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: Jenkins gem
|
27
|
+
email:
|
28
|
+
- viet@ooyala.com
|
29
|
+
executables:
|
30
|
+
- jenkins-cli
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- Gemfile
|
37
|
+
- README
|
38
|
+
- Rakefile
|
39
|
+
- TODO
|
40
|
+
- bin/jenkins-cli
|
41
|
+
- jenkins-cli.gemspec
|
42
|
+
- lib/add_executor.rb
|
43
|
+
- lib/build_details.rb
|
44
|
+
- lib/build_history.rb
|
45
|
+
- lib/disable_emails.rb
|
46
|
+
- lib/display_queue.rb
|
47
|
+
- lib/enable_emails.rb
|
48
|
+
- lib/grant_user.rb
|
49
|
+
- lib/groovy/add_slave.groovy
|
50
|
+
- lib/groovy/build_details.groovy
|
51
|
+
- lib/groovy/build_history.groovy
|
52
|
+
- lib/groovy/disable_email.groovy
|
53
|
+
- lib/groovy/display_queue.groovy
|
54
|
+
- lib/groovy/email_details.groovy
|
55
|
+
- lib/groovy/enable_email.groovy
|
56
|
+
- lib/groovy/grant_user.groovy
|
57
|
+
- lib/groovy/job_details.groovy
|
58
|
+
- lib/groovy/list_failing_jobs.groovy
|
59
|
+
- lib/groovy/list_nodes.groovy
|
60
|
+
- lib/groovy/modify_labels.groovy
|
61
|
+
- lib/groovy/nodes.groovy
|
62
|
+
- lib/groovy/stream_log.groovy
|
63
|
+
- lib/jenkins-cli.jar
|
64
|
+
- lib/jenkins-cli/version.rb
|
65
|
+
- lib/jenkins_controller.rb
|
66
|
+
- lib/job_details.rb
|
67
|
+
- lib/job_labels.rb
|
68
|
+
- lib/list_failing_jobs.rb
|
69
|
+
- lib/list_jobs.rb
|
70
|
+
- lib/start_job.rb
|
71
|
+
- lib/stream_log.rb
|
72
|
+
homepage: http://www.ooyala.com
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
rubyforge_project: jenkins-cli
|
95
|
+
rubygems_version: 1.8.11
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: This jenkins-cli gem is an internal tool to Ooyala for managing a Jenkins instance from the command
|
99
|
+
test_files: []
|
100
|
+
|