Class: Dply::Jenkins

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/dply/jenkins.rb

Instance Method Summary collapse

Methods included from Helper

#cmd, #error, #git, #logger, #sh, #symlink

Constructor Details

#initialize(url, project) ⇒ Jenkins

Returns a new instance of Jenkins.



10
11
12
13
14
# File 'lib/dply/jenkins.rb', line 10

def initialize(url, project)
  @url = URI.parse(url)
  @project = project
  validate
end

Instance Method Details

#latest_successful_revisionObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/dply/jenkins.rb', line 16

def latest_successful_revision
  api_url = "#{@url}/job/#{@project}/api/json"
  logger.debug "using jenkins api \"#{api_url}\""
  open(api_url) do |f|
    json = JSON.parse(f.read)
    revision = json["lastSuccessfulBuild"]["number"]
    logger.debug "got revision #{revision}"
    revision
  end
end

#validateObject



27
28
29
30
# File 'lib/dply/jenkins.rb', line 27

def validate
  raise "invalid uri " if not ["http", "https"].include? @url.scheme
  raise "project name not defined" if not @project
end