Class: JenkinsApi::CLI::Job
- Inherits:
-
Thor
- Object
- Thor
- JenkinsApi::CLI::Job
- Includes:
- Thor::Actions
- Defined in:
- lib/improved_jenkins_client/cli/job.rb
Overview
This class provides various command line operations related to jobs.
Instance Method Summary collapse
- #build(job) ⇒ Object
-
#console(job) ⇒ Object
CLI command to obtain console output for a job.
-
#delete(job) ⇒ Object
CLI command to delete a job.
-
#list ⇒ Object
CLI command to list all jobs in Jenkins or the ones matched by status or a regular expression.
-
#recreate(job) ⇒ Object
CLI command to recreate a job on Jenkins.
-
#restrict(job) ⇒ Object
CLI command to restrict a job to a node.
-
#status(job) ⇒ Object
CLI command to get the status of a job.
Instance Method Details
#build(job) ⇒ Object
66 67 68 69 |
# File 'lib/improved_jenkins_client/cli/job.rb', line 66 def build(job) @client = Helper.setup() @client.job.build(job, [:params], [:opts]) end |
#console(job) ⇒ Object
CLI command to obtain console output for a job. Make sure the log location is set to something other than STDOUT. By default it is set to STDOUT. If the log messages are printed on the same console, the console output will get garbled.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/improved_jenkins_client/cli/job.rb', line 101 def console(job) @client = Helper.setup() # Print progressive console output response = @client.job.get_console_output(job) puts response['output'] unless response['more'] while response['more'] size = response['size'] puts response['output'] unless response['output'].chomp.empty? sleep [:sleep].to_i if [:sleep] response = @client.job.get_console_output(job, 0, size) end # Print the last few lines puts response['output'] unless response['output'].chomp.empty? end |
#delete(job) ⇒ Object
CLI command to delete a job
86 87 88 89 |
# File 'lib/improved_jenkins_client/cli/job.rb', line 86 def delete(job) @client = Helper.setup() puts @client.job.delete(job) end |
#list ⇒ Object
CLI command to list all jobs in Jenkins or the ones matched by status or a regular expression
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/improved_jenkins_client/cli/job.rb', line 38 def list @client = Helper.setup() if [:filter] && [:status] name_filtered = @client.job.list([:filter]) puts @client.job.list_by_status([:status], name_filtered) elsif [:filter] puts @client.job.list([:filter]) elsif [:status] puts @client.job.list_by_status([:status]) else puts @client.job.list_all end end |
#recreate(job) ⇒ Object
CLI command to recreate a job on Jenkins
54 55 56 57 |
# File 'lib/improved_jenkins_client/cli/job.rb', line 54 def recreate(job) @client = Helper.setup() @client.job.recreate(job) end |
#restrict(job) ⇒ Object
CLI command to restrict a job to a node
122 123 124 125 126 127 128 129 |
# File 'lib/improved_jenkins_client/cli/job.rb', line 122 def restrict(job) @client = Helper.setup() if [:node] @client.job.restrict_to_node(job, [:node]) else say "You need to specify the node to be restricted to.", :red end end |