Class: JenkinsApi::CLI::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins_api_client/cli/helper.rb

Overview

This is the helper class that sets up the credentials from the command line parameters given and initializes the Jenkins API Client.

Class Method Summary (collapse)

Class Method Details

+ (JenkinsApi::Client) setup(options)

Sets up the credentials and initializes the Jenkins API Client

Parameters:

  • options (Hash)

    Options obtained from the command line

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jenkins_api_client/cli/helper.rb', line 36

def self.setup(options)
  if options[:username] && options[:server_ip] && \
    (options[:password] || options[:password_base64])
    creds = options
  elsif options[:creds_file]
    creds = YAML.load_file(
      File.expand_path(options[:creds_file], __FILE__)
    )
  elsif File.exist?("#{ENV['HOME']}/.jenkins_api_client/login.yml")
    creds = YAML.load_file(
      File.expand_path(
        "#{ENV['HOME']}/.jenkins_api_client/login.yml", __FILE__
      )
    )
  else
    msg = "Credentials are not set. Please pass them as parameters or"
    msg << " set them in the default credentials file"
    puts msg
    exit 1
  end
  JenkinsApi::Client.new(creds)
end