Class: JenkinsJob::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/jenkins_job/cli.rb

Instance Method Summary collapse

Instance Method Details

#clean(*project) ⇒ Object



41
42
43
44
45
# File 'lib/jenkins_job/cli.rb', line 41

def clean *project
  project.each do |p|
    Project.new(p).clean 
  end
end

#clone(*project) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jenkins_job/cli.rb', line 11

def clone *project
  force = options[:force] || false
  project.each do |p|
    # calculate the new dir
    new_dir = p.gsub(options[:original_branch],
                              options[:new_branch])
    
    if File.exists?(new_dir)
      if !force && !yes?("#{new_dir} already exists, delete it? [y/n]")
        say "#{p} -> #{new_dir} - skipped by user choice", :yellow
        next
      else
        FileUtils.rm_rf(new_dir)
      end
    end

    FileUtils.mkdir_p new_dir
    config_lines = File.open(File.join(p, 'config.xml'), 'r').readlines
    File.open(File.join(new_dir, 'config.xml'), 'w') do |file|
      config_lines.each do |line|
        file.write(line.gsub(options[:original_branch],
                             options[:new_branch]))
      end
    end
    say "#{p} -> #{new_dir} - done", :green
  end
end

#copy_setting(source_project, setting_name, *dest_project) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/jenkins_job/cli.rb', line 65

def copy_setting source_project, setting_name, *dest_project
  source = Project.new(source_project)
  setting = source.setting(setting_name)
  if setting.nil?
    say("#{source_project} doesn't contain the specified setting", :red)
    Kernel::exit(1)
  end

  dest_project.each do |p|
   dest = Project.new(p)
   dest.update_setting(setting_name, setting)
   say("#{setting_name} copied to #{p}", :green)
  end
end

#disable(*project) ⇒ Object



48
49
50
51
52
53
# File 'lib/jenkins_job/cli.rb', line 48

def disable *project
  project.each do |p|
    Project.new(p).disable
    puts "#{p} - disabled"
  end
end

#enable(*project) ⇒ Object



56
57
58
59
60
61
# File 'lib/jenkins_job/cli.rb', line 56

def enable *project
  project.each do |p|
    Project.new(p).enable
    puts "#{p} - enabled"
  end
end