Module: Jenkins::CLI::Command

Extended by:
Plugin::Behavior
Includes:
Extension
Defined in:
lib/jenkins/cli/command.rb

Overview

Extend the Jenkins CLI

Jenkins ships with a CLI which can be used to iteract with it from a terminal, or from a program. It also exposes an API with which developers can extend the CLI with their own commands.

The Ruby API allows you define a command as a Ruby class, which is then instantiated once for each invocation of the command via the CLI.

Argument parsing is flexible, and a parsing scheme (Slop) is provided by default, but this is optional behavior which can be overridden.

Include this to define a new CLI / SSHD command. Example:

class HelloWorldCommand
  include Jenkins::CLI::Command

  description "Hello world sample command"

  arguments do
    on :v, :verbose, 'Print verbosely'
    on :n, :name=, 'Set your name, if not Joe', :default => 'Joe'
  end

  run do
    puts "Hello #{options[:name]}!"
    if options.verbose?
      puts "It's currently #{Time.now}"
      puts "Very glad to see you! How are you doing today?"
    end
  end
end

This will create a Jenkins CLI command called ‘hello-world` Which can be used as

jenkins-cli hello-world --n cowboyd -v

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Method Summary

Methods included from Plugin::Behavior

extended, implemented, included

Methods included from Plugin::Behavior::BehavesAs

#behaves_as