58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/capistrano/recipes/deploy/strategy/jenkins_artifact.rb', line 58
def deploy!
dir_name = exists?(:is_multibranch_job) && fetch(:is_multibranch_job) ? fetch(:branch) : fetch(:build_project)
jenkins_origin = fetch(:jenkins_origin) or abort ":jenkins_origin configuration must be defined"
client = JenkinsApi::Client.new(server_url: jenkins_origin.to_s)
set(:artifact_url) do
uri = ''
if exists?(:artifact_relative_path)
uri = client.job.find_last_successful_artifact_with_path(dir_name, fetch(:artifact_relative_path))
else
uri = client.job.find_last_successful_artifact(dir_name)
end
abort "No artifact found for #{dir_name}" if uri.empty?
URI.parse(uri).tap {|uri|
uri.scheme = jenkins_origin.scheme
uri.host = jenkins_origin.host
uri.port = jenkins_origin.port
}.to_s
end
last_successful_build = client.job.get_last_successful_build(dir_name)
deploy_at = Time.at(last_successful_build['timestamp'] / 1000)
compression_type = fetch(
:artifact_compression_type,
_guess_compression_type(fetch(:artifact_url))
)
compression_switch = _compression_type_to_switch(compression_type)
tar_opts = []
strip_level = fetch(:artifact_strip_level, 1)
if strip_level && strip_level > 0
tar_opts << "--strip-components=#{strip_level}"
end
set(:release_name, deploy_at.strftime('%Y%m%d%H%M%S'))
set(:release_path, "#{fetch(:releases_path)}/#{fetch(:release_name)}")
set(:latest_release, fetch(:release_path))
run " mkdir -p \#{fetch(:release_path)} && \\\n (curl -s \#{fetch(:artifact_url)} | \\\n tar \#{tar_opts.join(' ')} -C \#{fetch(:release_path)} -\#{compression_switch}xf -)\n SCRIPT\nend\n"
|