Class: JenkinsApi::Client::System

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

Overview

This class is used to communicate with Jenkins and performing some admin level operations such as restarting and reloading Jenkins.

Instance Method Summary (collapse)

Constructor Details

- (System) initialize(client)

Initializes a new System object.

Parameters:

  • client (Client)

    the client object



38
39
40
41
42
# File 'lib/jenkins_api_client/system.rb', line 38

def initialize(client)
  @client = client
  @logger = @client.logger
  @timeout = @client.timeout
end

Instance Method Details

- (Object) cancel_quiet_down

Cancels the quiet doen request sent to the server.



59
60
61
62
# File 'lib/jenkins_api_client/system.rb', line 59

def cancel_quiet_down
  @logger.info "Cancelling jenkins form quiet down..."
  @client.api_post_request("/cancelQuietDown")
end

- (Object) list_users

List all users known to Jenkins by their Full Name



94
95
96
97
98
99
100
101
102
103
# File 'lib/jenkins_api_client/system.rb', line 94

def list_users
  warn "DEPRECATION: System#list_users is deprecated. Please use User#list instead"
  @logger.info "Obtaining the list of users from jenkins"
  users = @client.api_get_request("/asynchPeople")
  names = []
  users['users'].each { |user|
    names << user['user']['fullName']
  } unless users.nil?
  return names
end

- (Object) quiet_down

Sends a quiet down request to the server.



52
53
54
55
# File 'lib/jenkins_api_client/system.rb', line 52

def quiet_down
  @logger.info "Performing a quiet down of jenkins..."
  @client.api_post_request("/quietDown")
end

- (Object) reload

Reload the Jenkins server



87
88
89
90
# File 'lib/jenkins_api_client/system.rb', line 87

def reload
  @logger.info "Reloading jenkins..."
  @client.api_post_request("/reload")
end

- (Object) restart(force = false)

Restarts the Jenkins server

Parameters:

  • force (Boolean) (defaults to: false)

    whether to force restart or wait till all jobs are completed.



69
70
71
72
73
74
75
76
77
# File 'lib/jenkins_api_client/system.rb', line 69

def restart(force = false)
  if force
    @logger.info "Performing a force restart of jenkins..."
    @client.api_post_request("/restart")
  else
    @logger.info "Performing a safe restart of jenkins..."
    @client.api_post_request("/safeRestart")
  end
end

- (Object) restart!

Performs a force restart of Jenkins server



81
82
83
# File 'lib/jenkins_api_client/system.rb', line 81

def restart!
  restart(true)
end

- (Object) to_s

Returns a string representation of System class.



46
47
48
# File 'lib/jenkins_api_client/system.rb', line 46

def to_s
  "#<JenkinsApi::Client::System>"
end

- (Object) wait_for_ready

This method waits till the server becomes ready after a start or restart.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/jenkins_api_client/system.rb', line 108

def wait_for_ready
  Timeout::timeout(@timeout) do
    while true do
      response = @client.get_root
      @logger.info "Waiting for jenkins to restart..."
      if (response.body =~ /Please wait while Jenkins is restarting/ ||
        response.body =~ /Please wait while Jenkins is getting ready to work/)
        sleep 30
        redo
      else
        return true
      end
    end
  end
  false
end