43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
|
# File 'lib/autodeploy.rb', line 43
def run
@deployer = Autodeploy::Deployer.new(@config, job)
@deployer.run()
return unless job['result'] == 'SUCCESS'
build_action = job['actions'].detect{|action| action.include?('lastBuiltRevision')}
sha = build_action.nil? ? nil : build_action['lastBuiltRevision']['SHA1']
filename = [job_number, sha, job['artifacts'][0]['fileName']].compact.join('-')
filepath = File.join(@config['download_dir'], filename)
if File.exists?(filepath)
Autodeploy.log "#{filepath} already exists"
return
end
uri = URI("#{job['url']}artifact/#{job['artifacts'][0]['relativePath']}")
Autodeploy.log "Starting download: #{uri.path}"
Net::HTTP.start(uri.host, uri.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
request = Net::HTTP::Get.new uri.request_uri
request.basic_auth @config['username'], @config['password']
resp = http.request(request)
if resp.code != "200"
Autodeploy.log "Error downloading artifact: #{resp.code} - #{resp.message}"
return
end
Autodeploy.log "Saving #{filename}"
open("downloads/#{filename}", "wb") do |file|
file.write(resp.body)
Autodeploy.log "Completed download - #{filename}"
end
end
end
|