Class: JenkinsApi::Client::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/recipes/deploy/strategy/jenkins_artifact.rb

Instance Method Summary collapse

Instance Method Details

#find_last_successful_artifact(job_name) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/capistrano/recipes/deploy/strategy/jenkins_artifact.rb', line 22

def find_last_successful_artifact(job_name)
  last_successful_build  = get_last_successful_build(job_name)
  relative_build_path   = last_successful_build['artifacts'][0]['relativePath']
  jenkins_path          = last_successful_build['url']
  artifact_path         = URI.escape("#{jenkins_path}artifact/#{relative_build_path}")
  return artifact_path
end

#find_last_successful_artifact_with_path(job_name, relative_path) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/capistrano/recipes/deploy/strategy/jenkins_artifact.rb', line 12

def find_last_successful_artifact_with_path(job_name, relative_path)
  response_json = get_last_successful_build(job_name)
  if response_json['artifacts'].none? {|a| a['relativePath'] == relative_path }
    abort "Specified artifact not found in curent_build !!"
  end
  jenkins_path          = response_json['url']
  artifact_path         = URI.escape("#{jenkins_path}artifact/#{relative_path}")
  return artifact_path
end

#get_last_successful_build(job_name) ⇒ Object



7
8
9
10
# File 'lib/capistrano/recipes/deploy/strategy/jenkins_artifact.rb', line 7

def get_last_successful_build(job_name)
  @logger.info "Obtaining last successful build number of #{job_name}"
  @client.api_get_request("/job/#{path_encode(job_name)}/lastSuccessfulBuild")
end