27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/capistrano/recipes/deploy/strategy/jenkins_artifact.rb', line 27
def deploy!
jenkins_origin = fetch(:jenkins_origin) or abort ":jenkins_origin configuration must be defined"
artifact_relative_path = fetch(:artifact_relative_path)
client = JenkinsApi::Client.new(server_url: jenkins_origin.to_s)
set(:artifact_url) do
uri = ''
if artifact_relative_path
uri = client.job.find_artifact_with_path(fetch(:build_project), artifact_relative_path)
else
uri = client.job.find_artifact(fetch(:build_project))
end
abort "No artifact found for #{fetch(:build_project)}" 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
build_num = client.job.get_last_successful_build_number(fetch(:build_project), "origin/#{fetch(:branch)}")
timestamp = client.job.get_build_details(fetch(:build_project), build_num)['timestamp']
deploy_at = Time.at(timestamp / 1000)
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 --strip-components=1 -C \#{fetch(:release_path)} -jxf -)\n SCRIPT\nend\n"
|