capistrano-strategy-jenkins_artifact 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 744ee059d6ce8d3548ae4f3c5e30db351bb83a60
|
4
|
+
data.tar.gz: 47d593834c80450a81ea66d806ec93a50094a22d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eec41b4c0c6a02d098a35afb900a36a5c4331ec1edc1dd733d63fe09f330817bb6897b1d346f93969d9baa777b43beaf04155b7279d18c0ac3a3de4127d478db
|
7
|
+
data.tar.gz: ccb873421905baa73e518db02d672bf4d3cad9c12ee68f34c2af96349dbb4d8cafa1967f91dfab23f041d068b73a61c9440b0ba42d2457c0ecfd05e386de70b8
|
data/.travis.yml
CHANGED
@@ -4,6 +4,11 @@ cache:
|
|
4
4
|
- vendor/bundle
|
5
5
|
language: ruby
|
6
6
|
rvm:
|
7
|
-
- 2.
|
8
|
-
|
7
|
+
- 2.4.0
|
8
|
+
- 2.3.3
|
9
|
+
- 2.2.6
|
10
|
+
matrix:
|
11
|
+
allow_failures:
|
12
|
+
- rvm: 2.4.0 # Currently json.gem fails to build
|
13
|
+
before_install: gem install bundler
|
9
14
|
script: bundle exec rake test
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = "capistrano-strategy-jenkins_artifact"
|
4
|
-
spec.version = "0.2.
|
4
|
+
spec.version = "0.2.1"
|
5
5
|
spec.authors = ["aereal"]
|
6
6
|
spec.email = ["aereal@aereal.org"]
|
7
7
|
|
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.11"
|
21
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
22
|
spec.add_development_dependency "minitest", "~> 5.0"
|
23
|
+
spec.add_development_dependency "webmock"
|
23
24
|
end
|
@@ -4,16 +4,13 @@ require 'capistrano/recipes/deploy/strategy/base'
|
|
4
4
|
require 'jenkins_api_client'
|
5
5
|
|
6
6
|
class ::JenkinsApi::Client::Job
|
7
|
-
def
|
7
|
+
def get_last_successful_build(job_name)
|
8
8
|
@logger.info "Obtaining last successful build number of #{job_name}"
|
9
|
-
|
10
|
-
res['number']
|
9
|
+
@client.api_get_request("/job/#{path_encode(job_name)}/lastSuccessfulBuild")
|
11
10
|
end
|
12
11
|
|
13
|
-
def
|
14
|
-
|
15
|
-
job_path = "job/#{path_encode job_name}/"
|
16
|
-
response_json = @client.api_get_request("/#{job_path}#{current_build_number}")
|
12
|
+
def find_last_successful_artifact_with_path(job_name, relative_path)
|
13
|
+
response_json = get_last_successful_build(job_name)
|
17
14
|
if response_json['artifacts'].none? {|a| a['relativePath'] == relative_path }
|
18
15
|
abort "Specified artifact not found in curent_build !!"
|
19
16
|
end
|
@@ -21,9 +18,43 @@ class ::JenkinsApi::Client::Job
|
|
21
18
|
artifact_path = URI.escape("#{jenkins_path}artifact/#{relative_path}")
|
22
19
|
return artifact_path
|
23
20
|
end
|
21
|
+
|
22
|
+
def find_last_successful_artifact(job_name)
|
23
|
+
last_successful_build = get_last_successful_build(job_name)
|
24
|
+
relative_build_path = last_successful_build['artifacts'][0]['relativePath']
|
25
|
+
jenkins_path = last_successful_build['url']
|
26
|
+
artifact_path = URI.escape("#{jenkins_path}artifact/#{relative_build_path}")
|
27
|
+
return artifact_path
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::Strategy::Base
|
32
|
+
|
33
|
+
def _guess_compression_type(filename)
|
34
|
+
case filename.downcase
|
35
|
+
when /\.tar\.gz$/, /\.tgz$/
|
36
|
+
:gzip
|
37
|
+
when /\.tar\.bz2$/, /\.tbz$/
|
38
|
+
:bzip2
|
39
|
+
when /\.tar\.xz$/, /\.txz$/
|
40
|
+
:xz
|
41
|
+
when /\.tar$/
|
42
|
+
:raw
|
43
|
+
else
|
44
|
+
:bzip2
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def _compression_type_to_switch(type)
|
49
|
+
case type
|
50
|
+
when :gzip then 'z'
|
51
|
+
when :bzip2 then 'j'
|
52
|
+
when :xz then 'J'
|
53
|
+
when :raw then '' # raw tarball
|
54
|
+
else abort "Invalid compression type: #{type}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
27
58
|
def deploy!
|
28
59
|
dir_name = exists?(:is_multibranch_job) && fetch(:is_multibranch_job) ? fetch(:branch) : fetch(:build_project)
|
29
60
|
|
@@ -32,9 +63,9 @@ class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::St
|
|
32
63
|
set(:artifact_url) do
|
33
64
|
uri = ''
|
34
65
|
if exists?(:artifact_relative_path)
|
35
|
-
uri = client.job.
|
66
|
+
uri = client.job.find_last_successful_artifact_with_path(dir_name, fetch(:artifact_relative_path))
|
36
67
|
else
|
37
|
-
uri = client.job.
|
68
|
+
uri = client.job.find_last_successful_artifact(dir_name)
|
38
69
|
end
|
39
70
|
abort "No artifact found for #{dir_name}" if uri.empty?
|
40
71
|
URI.parse(uri).tap {|uri|
|
@@ -44,9 +75,14 @@ class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::St
|
|
44
75
|
}.to_s
|
45
76
|
end
|
46
77
|
|
47
|
-
|
48
|
-
|
49
|
-
|
78
|
+
last_successful_build = client.job.get_last_successful_build(dir_name)
|
79
|
+
deploy_at = Time.at(last_successful_build['timestamp'] / 1000)
|
80
|
+
|
81
|
+
compression_type = fetch(
|
82
|
+
:artifact_compression_type,
|
83
|
+
_guess_compression_type(fetch(:artifact_url))
|
84
|
+
)
|
85
|
+
compression_switch = _compression_type_to_switch(compression_type)
|
50
86
|
|
51
87
|
set(:release_name, deploy_at.strftime('%Y%m%d%H%M%S'))
|
52
88
|
set(:release_path, "#{fetch(:releases_path)}/#{fetch(:release_name)}")
|
@@ -55,7 +91,7 @@ class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::St
|
|
55
91
|
run <<-SCRIPT
|
56
92
|
mkdir -p #{fetch(:release_path)} && \
|
57
93
|
(curl -s #{fetch(:artifact_url)} | \
|
58
|
-
tar --strip-components=1 -C #{fetch(:release_path)}
|
94
|
+
tar --strip-components=1 -C #{fetch(:release_path)} -#{compression_switch}xf -)
|
59
95
|
SCRIPT
|
60
96
|
end
|
61
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-strategy-jenkins_artifact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aereal
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jenkins_api_client
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.
|
84
98
|
email:
|
85
99
|
- aereal@aereal.org
|
@@ -115,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
129
|
version: '0'
|
116
130
|
requirements: []
|
117
131
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.5.
|
132
|
+
rubygems_version: 2.5.2
|
119
133
|
signing_key:
|
120
134
|
specification_version: 4
|
121
135
|
summary: Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.
|