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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 144f11b2a0dead53db3e59b2f9d1a7b4749d7705
4
- data.tar.gz: 3c7c69e2b4ef44e096cf04e6557955961ada1667
3
+ metadata.gz: 9a5db36572a0cb054e66d71245118d6daa2aa93b
4
+ data.tar.gz: b8b8d7af57076fdc8a497934478ad52d4d70a2b4
5
5
  SHA512:
6
- metadata.gz: 47fac1367ade6516f8ed43c17d3550c2fd6c4b748d6a98d00e21bc6e873d1a027e8cace38191e28fa0b80377ea751c5cbd52a080aef06db3549251dee94a21ab
7
- data.tar.gz: dcef58a7c88d9a2a8bc80e840f70d6a8c910383bc13074fc75945f5609d3609941bdc0ecc11052f1e2857a6e13c296b3b23821de80cc4248702fc7bed05dd49f
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.
@@ -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.2"
4
+ spec.version = "0.3.0"
5
5
  spec.authors = ["aereal"]
6
6
  spec.email = ["aereal@aereal.org"]
7
7
 
@@ -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 get_last_successful_build(job_name)
8
- @logger.info "Obtaining last successful build number of #{job_name}"
9
- @client.api_get_request("/job/#{path_encode(job_name)}/lastSuccessfulBuild")
10
- end
11
-
12
- def find_last_successful_artifact_with_path(job_name, relative_path)
13
- response_json = get_last_successful_build(job_name)
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 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
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
- uri = ''
65
- if exists?(:artifact_relative_path)
66
- uri = client.job.find_last_successful_artifact_with_path(dir_name, fetch(:artifact_relative_path))
67
- else
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
- set(:release_name, deploy_at.strftime('%Y%m%d%H%M%S'))
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.2.2
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-10 00:00:00.000000000 Z
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.6.10
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.