capistrano-strategy-jenkins_artifact 0.2.2 → 0.3.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 +4 -4
- data/README.md +32 -0
- data/capistrano-strategy-jenkins_artifact.gemspec +1 -1
- data/lib/capistrano/recipes/deploy/strategy/jenkins_artifact.rb +26 -28
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a5db36572a0cb054e66d71245118d6daa2aa93b
|
4
|
+
data.tar.gz: b8b8d7af57076fdc8a497934478ad52d4d70a2b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afb7ace0e506779442a5c0cccdc8abffbfa3f277c1195e48129c0578984a8384fb29e63ae0f607b5451559119abcd157a28aef8b888c65a0b7eea36ea57f7f5c
|
7
|
+
data.tar.gz: 92c4db0b7d0419254396df95be93f67bc7d9cc04d983dc80562340f88628396810f613bedb0f16d62580943ffcb7619aa426d7e9a0546362f908158a9c81800c
|
data/README.md
CHANGED
@@ -38,6 +38,38 @@ set :is_multibranch_job, true
|
|
38
38
|
set :deploy_via, :jenkins_artifact
|
39
39
|
```
|
40
40
|
|
41
|
+
## Options
|
42
|
+
|
43
|
+
| name | type | required? | default value |
|
44
|
+
| ---- | ---- | --------- | ------------- |
|
45
|
+
| `jenkins_origin` | String | **Y** | N/A |
|
46
|
+
| `build_project` | String | **Y** | N/A |
|
47
|
+
| `is_multibranch_job` | Boolean | n | `nil` |
|
48
|
+
| `artifact_relative_path` | String | n | `nil` |
|
49
|
+
| `artifact_compression_type` | (see below) | n | guessed by artifact URL |
|
50
|
+
| `artifact_strip_level` | Numeric | n | `1` |
|
51
|
+
| `release_name_from` | (see below) | n | `:build_at` |
|
52
|
+
|
53
|
+
### Supported compression types
|
54
|
+
|
55
|
+
* gzip
|
56
|
+
* bzip2
|
57
|
+
* xz
|
58
|
+
* raw
|
59
|
+
|
60
|
+
### `release_name_from` option
|
61
|
+
|
62
|
+
You can set either `:build_at` (default) or `:deploy_at` to this option.
|
63
|
+
|
64
|
+
By default, this storategy will set release_name from the artifact's build timestamp. This behavior is different from Capistrano's default.
|
65
|
+
If you prefer Capistrano's default behavior (use current timestamp for release_name), set this option to `:deploy_at`.
|
66
|
+
|
67
|
+
## Options exposed by capistrano-strategy-jenkins_artifact
|
68
|
+
|
69
|
+
| name | type |
|
70
|
+
| ---- | ---- |
|
71
|
+
| `artifact_url` | String |
|
72
|
+
|
41
73
|
## Contributing
|
42
74
|
|
43
75
|
Bug reports and pull requests are welcome on GitHub at https://github.com/aereal/capistrano-strategy-jenkins_artifact.
|
@@ -4,27 +4,19 @@ require 'capistrano/recipes/deploy/strategy/base'
|
|
4
4
|
require 'jenkins_api_client'
|
5
5
|
|
6
6
|
class ::JenkinsApi::Client::Job
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
if response_json['artifacts'].none? {|a| a['relativePath'] == relative_path }
|
15
|
-
abort "Specified artifact not found in curent_build !!"
|
16
|
-
end
|
17
|
-
jenkins_path = response_json['url']
|
18
|
-
artifact_path = URI.escape("#{jenkins_path}artifact/#{relative_path}")
|
7
|
+
def self.get_artifact_url_by_build(build, &finder)
|
8
|
+
finder ||= ->(_) { true }
|
9
|
+
matched_artifact = build['artifacts'].find(&finder)
|
10
|
+
raise 'Specified artifact not found in current build !!' unless matched_artifact
|
11
|
+
relative_build_path = matched_artifact['relativePath']
|
12
|
+
jenkins_path = build['url']
|
13
|
+
artifact_path = URI.escape("#{jenkins_path}artifact/#{relative_build_path}")
|
19
14
|
return artifact_path
|
20
15
|
end
|
21
16
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
jenkins_path = last_successful_build['url']
|
26
|
-
artifact_path = URI.escape("#{jenkins_path}artifact/#{relative_build_path}")
|
27
|
-
return artifact_path
|
17
|
+
def get_last_successful_build(job_name)
|
18
|
+
@logger.info "Obtaining last successful build number of #{job_name}"
|
19
|
+
@client.api_get_request("/job/#{path_encode(job_name)}/lastSuccessfulBuild")
|
28
20
|
end
|
29
21
|
end
|
30
22
|
|
@@ -58,15 +50,22 @@ class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::St
|
|
58
50
|
def deploy!
|
59
51
|
dir_name = exists?(:is_multibranch_job) && fetch(:is_multibranch_job) ? fetch(:branch) : fetch(:build_project)
|
60
52
|
|
53
|
+
release_name_from = fetch(:release_name_from, :build_at)
|
54
|
+
if release_name_from != :build_at && release_name_from != :deploy_at
|
55
|
+
abort ':release_name_from must be either `:build_at` or `:deploy_at`'
|
56
|
+
end
|
57
|
+
|
61
58
|
jenkins_origin = fetch(:jenkins_origin) or abort ":jenkins_origin configuration must be defined"
|
62
59
|
client = JenkinsApi::Client.new(server_url: jenkins_origin.to_s)
|
60
|
+
|
61
|
+
last_successful_build = client.job.get_last_successful_build(dir_name)
|
62
|
+
build_at = Time.at(last_successful_build['timestamp'] / 1000)
|
63
|
+
|
63
64
|
set(:artifact_url) do
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
uri = client.job.find_last_successful_artifact(dir_name)
|
69
|
-
end
|
65
|
+
artifact_finder = exists?(:artifact_relative_path) ?
|
66
|
+
->(artifact) { artifact['relativePath'] == fetch(:artifact_relative_path) } :
|
67
|
+
->(artifact) { true }
|
68
|
+
uri = JenkinsApi::Client::Job.get_artifact_url_by_build(last_successful_build, &artifact_finder)
|
70
69
|
abort "No artifact found for #{dir_name}" if uri.empty?
|
71
70
|
URI.parse(uri).tap {|uri|
|
72
71
|
uri.scheme = jenkins_origin.scheme
|
@@ -75,9 +74,6 @@ class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::St
|
|
75
74
|
}.to_s
|
76
75
|
end
|
77
76
|
|
78
|
-
last_successful_build = client.job.get_last_successful_build(dir_name)
|
79
|
-
deploy_at = Time.at(last_successful_build['timestamp'] / 1000)
|
80
|
-
|
81
77
|
compression_type = fetch(
|
82
78
|
:artifact_compression_type,
|
83
79
|
_guess_compression_type(fetch(:artifact_url))
|
@@ -90,7 +86,9 @@ class ::Capistrano::Deploy::Strategy::JenkinsArtifact < ::Capistrano::Deploy::St
|
|
90
86
|
tar_opts << "--strip-components=#{strip_level}"
|
91
87
|
end
|
92
88
|
|
93
|
-
|
89
|
+
if release_name_from == :build_at
|
90
|
+
set(:release_name, build_at.strftime('%Y%m%d%H%M%S'))
|
91
|
+
end
|
94
92
|
set(:release_path, "#{fetch(:releases_path)}/#{fetch(:release_name)}")
|
95
93
|
set(:latest_release, fetch(:release_path))
|
96
94
|
|
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.
|
4
|
+
version: 0.3.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-05-
|
11
|
+
date: 2017-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jenkins_api_client
|
@@ -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.5.2
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: Capistrano 2 strategy that uses Jenkins' artifact as a distribution provider.
|