Class: Jenkins::Plugin::Tools::Release

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins/plugin/tools/release.rb

Overview

task for deploying a plugin

Instance Method Summary collapse

Constructor Details

#initialize(spec, hpi, snapshot) ⇒ Release

Returns a new instance of Release.



13
14
15
16
17
# File 'lib/jenkins/plugin/tools/release.rb', line 13

def initialize(spec,hpi,snapshot)
  @spec = spec
  @hpi = hpi  # hpi file to release
  @snapshot = snapshot # if true, deploy as a snapshot, otherwise as release
end

Instance Method Details

#check_error(rsp) ⇒ Object



19
20
21
22
23
# File 'lib/jenkins/plugin/tools/release.rb', line 19

def check_error(rsp)
  # in case of 401 Unauthorized, the server just resets the connection and Net::HTTP fails to parse the response,
  # so we don't really get any meaningful error message.
  rsp.value # TODO: is this how we check for the error?
end

#each_developerObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jenkins/plugin/tools/release.rb', line 25

def each_developer
  @spec.developers.each do |id, name|
    email = ''
    if name =~ /^(.*)<([^>]+)>$/
      name = $1
      email = $2.strip
    end

    yield id, name.strip, email
  end
end

#runObject



37
38
39
40
41
42
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
# File 'lib/jenkins/plugin/tools/release.rb', line 37

def run
  cred = Jenkins::CiOrg::Credential.new
  if !cred.has_credential? then
    raise Exception.new("no credential available to connect to jenkins-ci.org. Please create ~/.jenkins-ci.org. See https://wiki.jenkins-ci.org/display/JENKINS/Dot+Jenkins+Ci+Dot+Org")
  end

  proxy = if ENV['HTTP_PROXY'] || ENV['http_proxy']
            proxy_uri = URI.parse(ENV['HTTP_PROXY'] || ENV['http_proxy'])
            Net::HTTP::Proxy(proxy_uri.host,
                             proxy_uri.port,
                             proxy_uri.user,
                             proxy_uri.password)
          else
            Net::HTTP
          end
  http = proxy.new("repo.jenkins-ci.org")

  puts @snapshot ? "deploying as a snapshot. Run with the --release option to release it for real when you are ready" : "deploying as a release"
  puts "Generating POM"
  version = @snapshot ? @spec.version+"-SNAPSHOT" : @spec.version
  pom = ERB.new(File.read(File.dirname(__FILE__)+"/templates/release-pom.xml.erb")).result(binding)
  path = "/#{@snapshot?'snapshots':'releases'}/org/jenkins-ci/ruby-plugins/#{@spec.name}/#{version}/#{@spec.name}-#{version}"
  req = Net::HTTP::Put.new("#{path}.pom")
  req.body = pom
  req.basic_auth(cred.user_name,cred.password)
  check_error(http.request(req))

  puts "Uploading #{@hpi}"
  File.open(@hpi,'r') do |f|
    req = Net::HTTP::Put.new("#{path}.hpi")
    req.body_stream = f
    req.basic_auth(cred.user_name,cred.password)
    req.content_length = File.size(@hpi)
    check_error(http.request(req))
  end

  puts "See http://maven.jenkins-ci.org"+File.dirname(path)
end