capistrano-strategy-jenkins_artifact 0.3.0 → 0.4.0
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: 735fcaef2ef6c36ee11f1cbe77b41d8c6d65651e
|
4
|
+
data.tar.gz: 5b4a9cdd23177d053c78fe239ae49be6c3446436
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab11f0e76ba394e7db82a20ed3af0578938a221ed7b4d860fc03c3dc3994554bd70913f394243443493a38eb42f7f55603670abbb3ac77b964d4c167a2563a66
|
7
|
+
data.tar.gz: '08c7002716da41011cbe0a2c99aa7341a7e7d4fd00c2d8dfb5699e2ffb17f26e0bf8830f24d2d2a0b2f1350b089fb13e39edd51089e128c8c8368b6d32a1a5e2'
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Capistrano::Strategy::JenkinsArtifact [![Build Status][travis-badge]][travis-url]
|
1
|
+
# Capistrano::Strategy::JenkinsArtifact [![Build Status][travis-badge]][travis-url] [![Gem Version](https://badge.fury.io/rb/capistrano-strategy-jenkins_artifact.svg)](https://badge.fury.io/rb/capistrano-strategy-jenkins_artifact)
|
2
2
|
|
3
3
|
Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.
|
4
4
|
|
@@ -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.
|
4
|
+
spec.version = "0.4.0"
|
5
5
|
spec.authors = ["aereal"]
|
6
6
|
spec.email = ["aereal@aereal.org"]
|
7
7
|
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
16
16
|
spec.require_paths = ["lib"]
|
17
17
|
|
18
|
-
spec.add_runtime_dependency "
|
18
|
+
spec.add_runtime_dependency "json"
|
19
19
|
spec.add_development_dependency "capistrano", "< 3.0.0"
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.11"
|
21
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -1,26 +1,40 @@
|
|
1
1
|
require 'uri'
|
2
|
+
require 'net/https'
|
2
3
|
|
3
4
|
require 'capistrano/recipes/deploy/strategy/base'
|
4
|
-
require 'jenkins_api_client'
|
5
5
|
|
6
|
-
class ::
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::Strategy::Base
|
7
|
+
module ApiClient
|
8
|
+
# jenkins_origin: URI
|
9
|
+
# => Maybe[$parsed_body: Hash]
|
10
|
+
def self.get_last_successful_build(jenkins_origin, dir_name)
|
11
|
+
uri = jenkins_origin.clone
|
12
|
+
uri.path += "/job/#{URI.encode_www_form_component(dir_name)}/lastSuccessfulBuild/api/json"
|
13
|
+
req = Net::HTTP::Get.new(uri.path)
|
14
|
+
res = Net::HTTP.start(uri.host, uri.port) {|session|
|
15
|
+
session.use_ssl = uri.scheme == 'https'
|
16
|
+
session.request(req)
|
17
|
+
}
|
18
|
+
case res
|
19
|
+
when Net::HTTPSuccess
|
20
|
+
if /\Aapplication\/json\b/ === (res.content_type || '')
|
21
|
+
JSON.parse(res.body)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
15
25
|
end
|
16
26
|
|
17
|
-
|
18
|
-
|
19
|
-
|
27
|
+
module Helpers
|
28
|
+
def self.get_artifact_url_by_build(build, &finder)
|
29
|
+
finder ||= ->(_) { true }
|
30
|
+
matched_artifact = build['artifacts'].find(&finder)
|
31
|
+
raise 'Specified artifact not found in current build !!' unless matched_artifact
|
32
|
+
relative_build_path = matched_artifact['relativePath']
|
33
|
+
jenkins_path = build['url']
|
34
|
+
artifact_path = URI.escape("#{jenkins_path}artifact/#{relative_build_path}")
|
35
|
+
return artifact_path
|
36
|
+
end
|
20
37
|
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::Strategy::Base
|
24
38
|
|
25
39
|
def _guess_compression_type(filename)
|
26
40
|
case filename.downcase
|
@@ -56,16 +70,14 @@ class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::St
|
|
56
70
|
end
|
57
71
|
|
58
72
|
jenkins_origin = fetch(:jenkins_origin) or abort ":jenkins_origin configuration must be defined"
|
59
|
-
|
60
|
-
|
61
|
-
last_successful_build = client.job.get_last_successful_build(dir_name)
|
73
|
+
last_successful_build = ApiClient.get_last_successful_build(jenkins_origin, dir_name)
|
62
74
|
build_at = Time.at(last_successful_build['timestamp'] / 1000)
|
63
75
|
|
64
76
|
set(:artifact_url) do
|
65
77
|
artifact_finder = exists?(:artifact_relative_path) ?
|
66
78
|
->(artifact) { artifact['relativePath'] == fetch(:artifact_relative_path) } :
|
67
79
|
->(artifact) { true }
|
68
|
-
uri =
|
80
|
+
uri = Helpers.get_artifact_url_by_build(last_successful_build, &artifact_finder)
|
69
81
|
abort "No artifact found for #{dir_name}" if uri.empty?
|
70
82
|
URI.parse(uri).tap {|uri|
|
71
83
|
uri.scheme = jenkins_origin.scheme
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-strategy-jenkins_artifact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aereal
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
131
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.
|
132
|
+
rubygems_version: 2.6.11
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.
|