capistrano-strategy-jenkins_artifact 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3addf7c46228a59eccc217af84a8489ed2a4c95
4
+ data.tar.gz: 8e0fa3fbd1b572decd34393580c422005e98e954
5
+ SHA512:
6
+ metadata.gz: 6f5107194d420ca2e13eb0ff72fa575915872caaadd9b4051b6151d02b9fbf134473790a1b454b59504942286babd18f6e2923368a7e8d9eb032a7d946c26559
7
+ data.tar.gz: 2f99050499c31ecb04f90c79fd03903f9e709e960e4bb79b45f41e4602b45bd9c71f15630ee70ca81bad5523a5b2831cb60f7c1107abbda34ce9afa4601c96f8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ cache:
3
+ directories:
4
+ - vendor/bundle
5
+ language: ruby
6
+ rvm:
7
+ - 2.2.1
8
+ before_install: gem install bundler -v 1.11.2
9
+ script: bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-strategy-jenkins_artifact.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 aereal
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,40 @@
1
+ # Capistrano::Strategy::JenkinsArtifact [![Build Status][travis-badge]][travis-url]
2
+
3
+ Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'capistrano-strategy-jenkins_artifact'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install capistrano-strategy-jenkins_artifact
20
+
21
+ ## Usage
22
+
23
+ In your `Capfile` (`config/deploy.rb`, or `config/deploy/**/*.rb`):
24
+
25
+ ```ruby
26
+ set :deploy_via, :jenkins_artifact
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aereal/capistrano-strategy-jenkins_artifact.
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
37
+
38
+
39
+ [travis-url]: https://travis-ci.org/aereal/capistrano-strategy-jenkins_artifact
40
+ [travis-badge]: https://travis-ci.org/aereal/capistrano-strategy-jenkins_artifact.svg?branch=master
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "capistrano-strategy-jenkins_artifact"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["aereal"]
6
+ spec.email = ["aereal@aereal.org"]
7
+
8
+ spec.summary = %q{Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.}
9
+ spec.description = %q{Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.}
10
+ spec.homepage = "https://github.com/aereal/capistrano-strategy-jenkins_artifact"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.bindir = "exe"
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_runtime_dependency "jenkins_api_client"
19
+ spec.add_development_dependency "capistrano", "< 3.0.0"
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "minitest", "~> 5.0"
23
+ end
@@ -0,0 +1,60 @@
1
+ require 'uri'
2
+
3
+ require 'capistrano/recipes/deploy/strategy/base'
4
+ require 'jenkins_api_client'
5
+
6
+ class ::JenkinsApi::Client::Job
7
+ def get_last_successful_build_number(job_name, branch)
8
+ @logger.info "Obtaining last successful build number of #{job_name}"
9
+ res = @client.api_get_request("/job/#{path_encode(job_name)}/lastSuccessfulBuild")
10
+ res['number']
11
+ end
12
+
13
+ def find_artifact_with_path(job_name, relative_path)
14
+ current_build_number = get_current_build_number(job_name)
15
+ job_path = "job/#{path_encode job_name}/"
16
+ response_json = @client.api_get_request("/#{job_path}#{current_build_number}")
17
+ if response_json['artifacts'].none? {|a| a['relativePath'] == relative_path }
18
+ abort "Specified artifact not found in curent_build !!"
19
+ end
20
+ jenkins_path = response_json['url']
21
+ artifact_path = URI.escape("#{jenkins_path}artifact/#{relative_path}")
22
+ return artifact_path
23
+ end
24
+ end
25
+
26
+ class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::Strategy::Base
27
+ def deploy!
28
+ jenkins_origin = fetch(:jenkins_origin) or abort ":jenkins_origin configuration must be defined"
29
+ artifact_relative_path = fetch(:artifact_relative_path)
30
+ client = JenkinsApi::Client.new(server_url: jenkins_origin.to_s)
31
+ set(:artifact_url) do
32
+ uri = ''
33
+ if artifact_relative_path
34
+ uri = client.job.find_artifact_with_path(fetch(:build_project), artifact_relative_path)
35
+ else
36
+ uri = client.job.find_artifact(fetch(:build_project))
37
+ end
38
+ abort "No artifact found for #{fetch(:build_project)}" if uri.empty?
39
+ URI.parse(uri).tap {|uri|
40
+ uri.scheme = jenkins_origin.scheme
41
+ uri.host = jenkins_origin.host
42
+ uri.port = jenkins_origin.port
43
+ }.to_s
44
+ end
45
+
46
+ build_num = client.job.get_last_successful_build_number(fetch(:build_project), "origin/#{fetch(:branch)}")
47
+ timestamp = client.job.get_build_details(fetch(:build_project), build_num)['timestamp']
48
+ deploy_at = Time.at(timestamp / 1000)
49
+
50
+ set(:release_name, deploy_at.strftime('%Y%m%d%H%M%S'))
51
+ set(:release_path, "#{fetch(:releases_path)}/#{fetch(:release_name)}")
52
+ set(:latest_release, fetch(:release_path))
53
+
54
+ run <<-SCRIPT
55
+ mkdir -p #{fetch(:release_path)} && \
56
+ (curl -s #{fetch(:artifact_url)} | \
57
+ tar --strip-components=1 -C #{fetch(:release_path)} -jxf -)
58
+ SCRIPT
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-strategy-jenkins_artifact
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - aereal
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-05 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: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "<"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.
84
+ email:
85
+ - aereal@aereal.org
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - capistrano-strategy-jenkins_artifact.gemspec
97
+ - lib/capistrano/recipes/deploy/strategy/jenkins_artifact.rb
98
+ homepage: https://github.com/aereal/capistrano-strategy-jenkins_artifact
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.5.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.
122
+ test_files: []