jenkins-builder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +102 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/jk +5 -0
- data/jenkins-builder.gemspec +38 -0
- data/lib/jenkins/builder/app.rb +169 -0
- data/lib/jenkins/builder/cli.rb +102 -0
- data/lib/jenkins/builder/config.rb +74 -0
- data/lib/jenkins/builder/secret.rb +34 -0
- data/lib/jenkins/builder/version.rb +5 -0
- data/lib/jenkins/builder.rb +8 -0
- metadata +218 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 35e2e3b4886655a6ffc8278233940424cc21586d711aa04565407d4d32ec98c9
|
4
|
+
data.tar.gz: 2a03de504c5b28ce27b15abb4a8c8a8ec64e4fdfd21fedfaa2b9c3bd61bc3c95
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3beecf48e5b8b318b8c71137e5c2e6059ebd758aed7c9bf52b0a2a0568b22434194ad5519e323326619cbd9339df6773a15dab525de9307fed614870d95d31bf
|
7
|
+
data.tar.gz: ddb3a55e68e071d62f8f74715ef0953a3c3d897161b06de5dc615f705d3b24840f8dfd3c4d9cee4c33fd969289b84625d457129b1f4432b58fb7daeb5ce6721e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at liuxiang@ktjr.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jenkins-builder (0.1.0)
|
5
|
+
jenkins_api_client (~> 1.5.3)
|
6
|
+
pastel (~> 0.7.2)
|
7
|
+
security (~> 0.1.3)
|
8
|
+
thor (~> 0.20.0)
|
9
|
+
tty-spinner (~> 0.8.0)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
byebug (10.0.2)
|
15
|
+
coderay (1.1.2)
|
16
|
+
diff-lcs (1.3)
|
17
|
+
equatable (0.5.0)
|
18
|
+
jenkins_api_client (1.5.3)
|
19
|
+
json (>= 1.0)
|
20
|
+
mixlib-shellout (>= 1.1.0)
|
21
|
+
nokogiri (~> 1.6)
|
22
|
+
socksify (>= 1.7.0)
|
23
|
+
terminal-table (>= 1.4.0)
|
24
|
+
thor (>= 0.16.0)
|
25
|
+
json (2.1.0)
|
26
|
+
method_source (0.9.1)
|
27
|
+
mini_portile2 (2.3.0)
|
28
|
+
mixlib-shellout (2.4.0)
|
29
|
+
nokogiri (1.8.5)
|
30
|
+
mini_portile2 (~> 2.3.0)
|
31
|
+
pastel (0.7.2)
|
32
|
+
equatable (~> 0.5.0)
|
33
|
+
tty-color (~> 0.4.0)
|
34
|
+
pry (0.11.3)
|
35
|
+
coderay (~> 1.1.0)
|
36
|
+
method_source (~> 0.9.0)
|
37
|
+
pry-byebug (3.6.0)
|
38
|
+
byebug (~> 10.0)
|
39
|
+
pry (~> 0.10)
|
40
|
+
pry-doc (0.13.4)
|
41
|
+
pry (~> 0.11)
|
42
|
+
yard (~> 0.9.11)
|
43
|
+
rake (10.5.0)
|
44
|
+
rspec (3.8.0)
|
45
|
+
rspec-core (~> 3.8.0)
|
46
|
+
rspec-expectations (~> 3.8.0)
|
47
|
+
rspec-mocks (~> 3.8.0)
|
48
|
+
rspec-core (3.8.0)
|
49
|
+
rspec-support (~> 3.8.0)
|
50
|
+
rspec-expectations (3.8.2)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.8.0)
|
53
|
+
rspec-mocks (3.8.0)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.8.0)
|
56
|
+
rspec-support (3.8.0)
|
57
|
+
security (0.1.3)
|
58
|
+
socksify (1.7.1)
|
59
|
+
terminal-table (1.8.0)
|
60
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
61
|
+
thor (0.20.0)
|
62
|
+
tty-color (0.4.3)
|
63
|
+
tty-cursor (0.6.0)
|
64
|
+
tty-spinner (0.8.0)
|
65
|
+
tty-cursor (>= 0.5.0)
|
66
|
+
unicode-display_width (1.4.0)
|
67
|
+
yard (0.9.16)
|
68
|
+
|
69
|
+
PLATFORMS
|
70
|
+
ruby
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
bundler (~> 1.16)
|
74
|
+
jenkins-builder!
|
75
|
+
pry (~> 0.11.3)
|
76
|
+
pry-byebug (~> 3.6.0)
|
77
|
+
pry-doc (~> 0.13.4)
|
78
|
+
rake (~> 10.0)
|
79
|
+
rspec (~> 3.0)
|
80
|
+
|
81
|
+
BUNDLED WITH
|
82
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Liu Xiang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# jenkins-builder
|
2
|
+
|
3
|
+
`jenkins-builder` is a gem for submit jenkins building tasks from command line.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
1. The gem use macOS KeyChain for managing credentials for logging into jenkins website, so macOS is the only supported OS by now.
|
8
|
+
2. It use the `fzf` fuzzy selecting utility to filter jenkins job names and git branches, so before using this gem, you should install `fzf` first: `brew install fzf`.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
$ gem install jenkins-builder
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
### Getting help information
|
17
|
+
|
18
|
+
$ jk help
|
19
|
+
|
20
|
+
### Setup
|
21
|
+
|
22
|
+
All configuration is stored in `$HOME/.jenkins-builder.yaml` except password.
|
23
|
+
|
24
|
+
Password is stored in macOS KeyChain, its service name is `jenkins-builder-credentials`.
|
25
|
+
|
26
|
+
#### Setup URL and credentials interactively
|
27
|
+
|
28
|
+
Just run: `$ jk setup`
|
29
|
+
|
30
|
+
#### Show settings information
|
31
|
+
|
32
|
+
$ jk info
|
33
|
+
|
34
|
+
By default, it does now show password, but if you want it: `$ jk info -p`
|
35
|
+
|
36
|
+
#### Edit config file directly
|
37
|
+
|
38
|
+
# jk setup -e
|
39
|
+
|
40
|
+
### Build
|
41
|
+
|
42
|
+
#### Specify job identifiers as command line arguments
|
43
|
+
|
44
|
+
$ jk build project1 project2 ...
|
45
|
+
|
46
|
+
#### Specify git brand if you use mbranch plugin
|
47
|
+
|
48
|
+
$ jk build project:origin/develop project2:origin/master ...
|
49
|
+
|
50
|
+
#### Suppress console output of build
|
51
|
+
|
52
|
+
$ jk build -s project1 ...
|
53
|
+
|
54
|
+
#### Use fzf to filter job names (project names) or git branch names
|
55
|
+
|
56
|
+
Just run `jk build` without job identifiers specified as command line arguments:
|
57
|
+
|
58
|
+
$ jk build
|
59
|
+
|
60
|
+
Even just (because `build` is the default task):
|
61
|
+
|
62
|
+
$ jk
|
63
|
+
|
64
|
+
### Alias
|
65
|
+
|
66
|
+
For most working jobs, you can create aliases for them for convenice.
|
67
|
+
|
68
|
+
#### Create an alias
|
69
|
+
|
70
|
+
$ jk alias p1 project1:origin/develop
|
71
|
+
|
72
|
+
then you could just run:
|
73
|
+
|
74
|
+
$ jk p1
|
75
|
+
|
76
|
+
it's equivalent to run `jk build project1:origin/develop`
|
77
|
+
|
78
|
+
#### List aliases
|
79
|
+
|
80
|
+
$ jk alias
|
81
|
+
|
82
|
+
#### Delete an alias
|
83
|
+
|
84
|
+
$ jk unalias p1
|
85
|
+
|
86
|
+
## Development
|
87
|
+
|
88
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
89
|
+
|
90
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lululau/jenkins-builder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
95
|
+
|
96
|
+
## License
|
97
|
+
|
98
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
99
|
+
|
100
|
+
## Code of Conduct
|
101
|
+
|
102
|
+
Everyone interacting in the Jenkins::Builder project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lululau/jenkins-builder/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jenkins/builder"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/jk
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "jenkins/builder/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jenkins-builder"
|
8
|
+
spec.version = Jenkins::Builder::VERSION
|
9
|
+
spec.authors = ["Liu Xiang"]
|
10
|
+
spec.email = ["liuxiang921@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %{Build Jenkins Jobs}
|
13
|
+
spec.description = %{Build Jenkins Jobs}
|
14
|
+
spec.homepage = "https://github.com/lululau/jenkins-builder"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency 'thor', '~> 0.20.0'
|
27
|
+
spec.add_dependency 'jenkins_api_client', '~> 1.5.3'
|
28
|
+
spec.add_dependency 'security', '~> 0.1.3'
|
29
|
+
spec.add_dependency 'pastel', '~> 0.7.2'
|
30
|
+
spec.add_dependency 'tty-spinner', '~> 0.8.0'
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_development_dependency "pry", "~> 0.11.3"
|
36
|
+
spec.add_development_dependency "pry-doc", "~> 0.13.4"
|
37
|
+
spec.add_development_dependency "pry-byebug", "~> 3.6.0"
|
38
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'jenkins/builder/cli'
|
2
|
+
require 'jenkins/builder/config'
|
3
|
+
require 'jenkins/builder/secret'
|
4
|
+
require 'jenkins_api_client'
|
5
|
+
require 'pastel'
|
6
|
+
require 'tty-spinner'
|
7
|
+
|
8
|
+
module Jenkins
|
9
|
+
module Builder
|
10
|
+
class App
|
11
|
+
|
12
|
+
attr_accessor :config, :secret, :client, :options
|
13
|
+
|
14
|
+
def initialize(options={})
|
15
|
+
@options = options
|
16
|
+
@config = Jenkins::Builder::Config.new
|
17
|
+
@secret = Jenkins::Builder::Secret.new
|
18
|
+
|
19
|
+
if @config.url && @config.username && @secret.password
|
20
|
+
@client = JenkinsApi::Client.new(server_url: @config.url,
|
21
|
+
username: @config.username,
|
22
|
+
password: @secret.password)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def main(args)
|
27
|
+
validate_os!
|
28
|
+
validate_fzf!
|
29
|
+
Jenkins::Builder::CLI.create_alias_commands(@config.aliases || [])
|
30
|
+
Jenkins::Builder::CLI.start(args)
|
31
|
+
rescue => e
|
32
|
+
STDERR.puts(e.message)
|
33
|
+
end
|
34
|
+
|
35
|
+
def setup(options)
|
36
|
+
validate_credentials!(options)
|
37
|
+
|
38
|
+
config.url = options[:url]
|
39
|
+
config.username = options[:username]
|
40
|
+
config.branches = options[:branches]
|
41
|
+
config.save!
|
42
|
+
|
43
|
+
secret.username = options[:username]
|
44
|
+
secret.password = options[:password]
|
45
|
+
secret.save!
|
46
|
+
|
47
|
+
puts 'Credentials setup successfully.'
|
48
|
+
end
|
49
|
+
|
50
|
+
def print_info(options)
|
51
|
+
puts <<-INFO.gsub(/^\s*/, '')
|
52
|
+
URL: #{@config.url}
|
53
|
+
Username: #{@config.username}
|
54
|
+
INFO
|
55
|
+
|
56
|
+
puts "Password: #{@secret.password}" if options[:password]
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_alias(name, job)
|
60
|
+
@config.aliases ||= {}
|
61
|
+
@config.aliases[name] = job
|
62
|
+
@config.save!
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete_alias(name)
|
66
|
+
if @config.aliases.nil? || @config.aliases.empty?
|
67
|
+
return
|
68
|
+
end
|
69
|
+
|
70
|
+
@config.aliases.delete(name)
|
71
|
+
@config.save!
|
72
|
+
end
|
73
|
+
|
74
|
+
def list_aliases
|
75
|
+
p @config.aliases
|
76
|
+
end
|
77
|
+
|
78
|
+
def build_each(jobs)
|
79
|
+
jobs.each { |job| build(job) }
|
80
|
+
end
|
81
|
+
|
82
|
+
def build(job)
|
83
|
+
job_name, branch = job.split(':')
|
84
|
+
latest_build_no = @client.job.get_current_build_number(job_name)
|
85
|
+
start_build(job_name, branch)
|
86
|
+
check_and_show_result(job_name, latest_build_no)
|
87
|
+
end
|
88
|
+
|
89
|
+
def all_jobs
|
90
|
+
@client.job.list_all
|
91
|
+
end
|
92
|
+
|
93
|
+
def all_branches
|
94
|
+
@config.branches
|
95
|
+
end
|
96
|
+
|
97
|
+
def job_detail(job_name)
|
98
|
+
@client.job.list_details(job_name)
|
99
|
+
end
|
100
|
+
|
101
|
+
def use_mbranch?(job_name)
|
102
|
+
job_detail(job_name).to_s =~ /mbranch/
|
103
|
+
end
|
104
|
+
|
105
|
+
def start_build(job_name, branch)
|
106
|
+
if use_mbranch?(job_name)
|
107
|
+
msg = "#{job_name} with branch #{branch}"
|
108
|
+
mbranch_param = {name: 'mbranch', value: branch}
|
109
|
+
params = mbranch_param.merge(json: {parameter: mbranch_param}.to_json)
|
110
|
+
@client.api_post_request("/job/#{job_name}/build?delay=0sec", params, true)
|
111
|
+
else
|
112
|
+
msg = job_name
|
113
|
+
@client.api_post_request("/job/#{job_name}/build?delay=0sec")
|
114
|
+
end
|
115
|
+
puts Pastel.new.cyan.bold("\n%s%s %s %s%s\n" % [' '*30, '★ '*5, msg, '★ '*5, ' '*30])
|
116
|
+
end
|
117
|
+
|
118
|
+
def check_and_show_result(job_name, latest_build_no)
|
119
|
+
while (build_no = @client.job.get_current_build_number(job_name)) <= latest_build_no
|
120
|
+
sleep 1
|
121
|
+
end
|
122
|
+
printed_size = 0
|
123
|
+
if @options[:silent]
|
124
|
+
spinner = TTY::Spinner.new(':spinner Building ...', format: :bouncing_ball)
|
125
|
+
spinner.auto_spin
|
126
|
+
end
|
127
|
+
loop do
|
128
|
+
console_output = @client.job.get_console_output(job_name, build_no, printed_size, 'text')
|
129
|
+
print console_output['output'].gsub("\r", '') unless @options[:silent]
|
130
|
+
printed_size += console_output['size'].to_i
|
131
|
+
break unless console_output['more']
|
132
|
+
sleep 2
|
133
|
+
end
|
134
|
+
if @options[:silent]
|
135
|
+
spinner.stop
|
136
|
+
end
|
137
|
+
status = @client.job.get_build_details(job_name, build_no)
|
138
|
+
msg = "Build Result: [#{status['result']}]"
|
139
|
+
pastel = Pastel.new
|
140
|
+
if msg =~ /SUCCESS/
|
141
|
+
puts pastel.green.bold(msg)
|
142
|
+
else
|
143
|
+
puts pastel.red.bold(msg)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
|
149
|
+
def validate_os!
|
150
|
+
raise 'Darwin is the only supported OS now.' unless `uname`.chomp == 'Darwin'
|
151
|
+
end
|
152
|
+
|
153
|
+
def validate_fzf!
|
154
|
+
`fzf --version`
|
155
|
+
rescue Errno::ENOENT
|
156
|
+
raise 'Required command fzf is not installed.'
|
157
|
+
end
|
158
|
+
|
159
|
+
def validate_credentials!(options)
|
160
|
+
@client = JenkinsApi::Client.new(server_url: options[:url],
|
161
|
+
username: options[:username],
|
162
|
+
password: options[:password])
|
163
|
+
@client.job.list_all
|
164
|
+
rescue JenkinsApi::Exceptions::Unauthorized => e
|
165
|
+
raise e.message
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'io/console'
|
3
|
+
|
4
|
+
module Jenkins
|
5
|
+
module Builder
|
6
|
+
class CLI < ::Thor
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def create_alias_commands(aliases)
|
10
|
+
aliases.each do |name, job|
|
11
|
+
desc "#{name}", "alias for: #{job}"
|
12
|
+
define_method name do
|
13
|
+
Jenkins::Builder::App.new.build(job)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'setup [-e]', 'Setup URL, username and password, or open config file in an editor when -e specified.'
|
20
|
+
option :edit, type: :boolean, aliases: ['-e']
|
21
|
+
def setup
|
22
|
+
if options[:edit]
|
23
|
+
editor = ENV['VISUAL'] || ENV['EDITOR'] || "vim"
|
24
|
+
exec("#{editor} #{File.expand_path('~/.jenkins-builder.yaml')}")
|
25
|
+
else
|
26
|
+
url = read_text('Input Jenkins URL: ')
|
27
|
+
username = read_text('Input Username: ')
|
28
|
+
password = read_password('Input Password: ')
|
29
|
+
git_branches = read_text('Input Git Branches: ').split(/\s*,\s*/)
|
30
|
+
|
31
|
+
Jenkins::Builder::App.new.setup(url: url, username: username, password: password, branches: git_branches)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'info [-p]', 'Show saved URL, username, use -p to show password also.'
|
36
|
+
option :password, type: :boolean, aliases: ['-p']
|
37
|
+
def info
|
38
|
+
Jenkins::Builder::App.new.print_info(options)
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'build [-s] <JOB_IDENTIFIERS>', 'Build jobs'
|
42
|
+
option :silent, type: :boolean, aliases: ['-s']
|
43
|
+
def build(*jobs)
|
44
|
+
app = Jenkins::Builder::App.new(silent: options[:silent])
|
45
|
+
if jobs.empty?
|
46
|
+
jobs = fzf(app.all_jobs)
|
47
|
+
exit if jobs.empty?
|
48
|
+
job = jobs.first
|
49
|
+
|
50
|
+
if app.use_mbranch?(job)
|
51
|
+
branches = fzf(app.all_branches)
|
52
|
+
exit if branches.empty?
|
53
|
+
branch = branches.first
|
54
|
+
jobs = [format('%s:%s', job, branch)]
|
55
|
+
else
|
56
|
+
jobs = [job]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
puts "Jobs: #{jobs.join(", ")}"
|
60
|
+
app.build_each(jobs)
|
61
|
+
end
|
62
|
+
|
63
|
+
desc 'alias <ALIAS> <JOB_IDENTIFIER>', 'Create job alias'
|
64
|
+
def alias(name=nil, job=nil)
|
65
|
+
if name.nil? || job.nil?
|
66
|
+
Jenkins::Builder::App.new.list_aliases
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
Jenkins::Builder::App.new.create_alias(name, job)
|
70
|
+
end
|
71
|
+
|
72
|
+
desc 'unalias <ALIAS>', 'Delete alias'
|
73
|
+
def unalias(name)
|
74
|
+
Jenkins::Builder::App.new.delete_alias(name)
|
75
|
+
end
|
76
|
+
|
77
|
+
default_task :build
|
78
|
+
|
79
|
+
no_commands do
|
80
|
+
def read_text(prompt)
|
81
|
+
print "#{prompt}"
|
82
|
+
result = STDIN.gets.chomp
|
83
|
+
result
|
84
|
+
end
|
85
|
+
|
86
|
+
def read_password(prompt)
|
87
|
+
print "#{prompt}"
|
88
|
+
result = STDIN.noecho(&:gets).chomp
|
89
|
+
puts
|
90
|
+
result
|
91
|
+
end
|
92
|
+
|
93
|
+
def fzf(lines)
|
94
|
+
IO.popen('fzf', 'r+') do |p|
|
95
|
+
p.puts(lines.join("\n"))
|
96
|
+
p.readlines.map(&:chomp)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Jenkins
|
4
|
+
module Builder
|
5
|
+
class Config
|
6
|
+
|
7
|
+
attr_accessor :file, :config
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
|
11
|
+
@file = File.expand_path('~/.jenkins-builder.yaml')
|
12
|
+
|
13
|
+
if File.exist?(@file)
|
14
|
+
@config = load(@file)
|
15
|
+
else
|
16
|
+
init
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def username
|
21
|
+
@config['username']
|
22
|
+
end
|
23
|
+
|
24
|
+
def username=(name)
|
25
|
+
@config['username'] = name
|
26
|
+
end
|
27
|
+
|
28
|
+
def aliases
|
29
|
+
@config['aliases']
|
30
|
+
end
|
31
|
+
|
32
|
+
def aliases=(aliases)
|
33
|
+
@config['aliases'] = aliases
|
34
|
+
end
|
35
|
+
|
36
|
+
def url
|
37
|
+
@config['url']
|
38
|
+
end
|
39
|
+
|
40
|
+
def url=(url)
|
41
|
+
@config['url'] = url
|
42
|
+
end
|
43
|
+
|
44
|
+
def branches
|
45
|
+
@config['branches']
|
46
|
+
end
|
47
|
+
|
48
|
+
def branches=(branches)
|
49
|
+
@config['branches'] = branches
|
50
|
+
end
|
51
|
+
|
52
|
+
def init
|
53
|
+
@config = {}
|
54
|
+
save(@config, @file)
|
55
|
+
end
|
56
|
+
|
57
|
+
def load(file)
|
58
|
+
YAML.load(File.read(file)) || {}
|
59
|
+
end
|
60
|
+
|
61
|
+
def save(config, file)
|
62
|
+
File.open(file, 'w') do |f|
|
63
|
+
unless @config.empty?
|
64
|
+
f.write(YAML.dump(config))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def save!
|
70
|
+
save(@config, @file)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'security'
|
2
|
+
|
3
|
+
module Jenkins
|
4
|
+
module Builder
|
5
|
+
class Secret
|
6
|
+
|
7
|
+
SERVICE = 'jenkins-builder-credentials'
|
8
|
+
|
9
|
+
attr_accessor :username, :password
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
if credentials = load
|
13
|
+
@username = credentials[:username]
|
14
|
+
@password = credentials[:password]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def load
|
19
|
+
if result = Security::GenericPassword.find(service: SERVICE)
|
20
|
+
{username: result.attributes['acct'], password: result.password}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def save!
|
25
|
+
delete
|
26
|
+
Security::GenericPassword.add(SERVICE, @username, @password)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete
|
30
|
+
Security::GenericPassword.delete(service: SERVICE)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jenkins-builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Liu Xiang
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.20.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.20.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jenkins_api_client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.5.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.5.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: security
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pastel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.7.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tty-spinner
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.8.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.8.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.16'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.16'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.11.3
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.11.3
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry-doc
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.13.4
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.13.4
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry-byebug
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 3.6.0
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 3.6.0
|
167
|
+
description: Build Jenkins Jobs
|
168
|
+
email:
|
169
|
+
- liuxiang921@gmail.com
|
170
|
+
executables:
|
171
|
+
- jk
|
172
|
+
extensions: []
|
173
|
+
extra_rdoc_files: []
|
174
|
+
files:
|
175
|
+
- ".gitignore"
|
176
|
+
- ".rspec"
|
177
|
+
- ".travis.yml"
|
178
|
+
- CODE_OF_CONDUCT.md
|
179
|
+
- Gemfile
|
180
|
+
- Gemfile.lock
|
181
|
+
- LICENSE.txt
|
182
|
+
- README.md
|
183
|
+
- Rakefile
|
184
|
+
- bin/console
|
185
|
+
- bin/setup
|
186
|
+
- exe/jk
|
187
|
+
- jenkins-builder.gemspec
|
188
|
+
- lib/jenkins/builder.rb
|
189
|
+
- lib/jenkins/builder/app.rb
|
190
|
+
- lib/jenkins/builder/cli.rb
|
191
|
+
- lib/jenkins/builder/config.rb
|
192
|
+
- lib/jenkins/builder/secret.rb
|
193
|
+
- lib/jenkins/builder/version.rb
|
194
|
+
homepage: https://github.com/lululau/jenkins-builder
|
195
|
+
licenses:
|
196
|
+
- MIT
|
197
|
+
metadata: {}
|
198
|
+
post_install_message:
|
199
|
+
rdoc_options: []
|
200
|
+
require_paths:
|
201
|
+
- lib
|
202
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - ">="
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
212
|
+
requirements: []
|
213
|
+
rubyforge_project:
|
214
|
+
rubygems_version: 2.7.7
|
215
|
+
signing_key:
|
216
|
+
specification_version: 4
|
217
|
+
summary: Build Jenkins Jobs
|
218
|
+
test_files: []
|