Class: JenkinsLauncher::CLI
- Inherits:
-
Thor
- Object
- Thor
- JenkinsLauncher::CLI
- Defined in:
- lib/jenkins_launcher/cli.rb
Instance Method Summary collapse
- #attach(config_file) ⇒ Object
- #console(config_file) ⇒ Object
- #create(config_file) ⇒ Object
- #destroy(config_file) ⇒ Object
-
#initialize(arg1, arg2, arg3) ⇒ CLI
constructor
A new instance of CLI.
- #start(config_file) ⇒ Object
- #stop(config_file) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(arg1, arg2, arg3) ⇒ CLI
Returns a new instance of CLI.
40 41 42 43 44 |
# File 'lib/jenkins_launcher/cli.rb', line 40 def initialize(arg1, arg2, arg3) super @api = APIInterface.new() @config = ConfigLoader.new end |
Instance Method Details
#attach(config_file) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/jenkins_launcher/cli.rb', line 116 def attach(config_file) params = @config.load_config(config_file) if !@api.job_exists?(params[:name]) puts "Job is not created. Please use the 'start' command to create and build the job.".red elsif !@api.job_building?(params[:name]) puts "Job is not running. Please use the 'start' command to build the job.".yellow else refresh_rate = [:refresh_rate] ? [:refresh_rate].to_i : 5 @api.display_progressive_console_output(params[:name], refresh_rate) print_status(@api.get_job_status(params[:name])) @api.delete_job(params[:name]) if [:delete_after] end end |
#console(config_file) ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/jenkins_launcher/cli.rb', line 131 def console(config_file) params = @config.load_config(config_file) if !@api.job_exists?(params[:name]) puts "Job is not created. Please use the 'create' or 'start' command to create or/and build the job.".red elsif @api.job_building?(params[:name]) puts "The job is currently building. Please use the 'attach' command to attach to the running build and watch progress".yellow else @api.display_progressive_console_output(params[:name], 5) end end |
#create(config_file) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/jenkins_launcher/cli.rb', line 67 def create(config_file) params = @config.load_config(config_file) unless @api.job_exists?(params[:name]) @api.create_job(params) @api.use_node(params[:name], params[:node]) if params[:node] puts "The Job '#{params[:name]}' is created successfully.".green else puts "The job is already created. Please use 'start' command to build the job.".yellow end end |
#destroy(config_file) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/jenkins_launcher/cli.rb', line 144 def destroy(config_file) params = @config.load_config(config_file) if !@api.job_exists?(params[:name]) puts "The job doesn't exist or already destroyed.".yellow elsif @api.job_building?(params[:name]) && ![:force] msg = '' msg << "The job is currently building. Please use the 'stop' command or wait until the build is completed." msg << " The --force option can be used to stop the build and destroy immediately." msg << " If you would like to watch the progress, use the 'attach' command." puts msg.yellow else @api.stop_job(params[:name]) if [:force] && @api.job_building?(params[:name]) @api.delete_job(params[:name]) puts "The job '#{params[:name]}' is destroyed successfully.".green end end |
#start(config_file) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/jenkins_launcher/cli.rb', line 82 def start(config_file) params = @config.load_config(config_file) unless @api.job_exists?(params[:name]) @api.create_job(params) @api.use_node(params[:name], params[:node]) if params[:node] end unless @api.job_building?(params[:name]) @api.build_job(params[:name]) quiet_period = [:quiet_period] ? [:quiet_period] : 5 sleep quiet_period refresh_rate = [:refresh_rate] ? [:refresh_rate].to_i : 5 @api.display_progressive_console_output(params[:name], refresh_rate) print_status(@api.get_job_status(params[:name])) @api.delete_job(params[:name]) if [:delete_after] else puts "Build is already running. Run 'attach' command to attach to existing build and watch progress.".yellow end end |
#stop(config_file) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/jenkins_launcher/cli.rb', line 102 def stop(config_file) params = @config.load_config(config_file) if !@api.job_exists?(params[:name]) puts "The job doesn't exist".red elsif !@api.job_building?(params[:name]) puts "The job is currently not building or it may have finished already.".yellow else @api.stop_job(params[:name]) end end |
#version ⇒ Object
62 63 64 |
# File 'lib/jenkins_launcher/cli.rb', line 62 def version puts JenkinsLauncher::VERSION end |