Class: JenkinsApi::Client::System

Inherits:
Object
  • Object
show all
Defined in:
lib/improved_jenkins_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

#initialize(client) ⇒ System

Initializes a new System object.

Parameters:

  • client (Client)

    the client object



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

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

Instance Method Details

#cancel_quiet_downObject

Cancels the quiet down request sent to the server.



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

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

#check_quiet_down?Boolean

Checks if server is in quiet down mode.

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/improved_jenkins_client/system.rb', line 66

def check_quiet_down?
  @logger.info "Checking if jenkins is in quiet down mode..."
  @client.root.quieting_down?
end

#list_usersObject

List all users known to Jenkins by their Full Name



101
102
103
104
105
106
107
108
109
110
# File 'lib/improved_jenkins_client/system.rb', line 101

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

#quiet_downObject

Sends a quiet down request to the server.



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

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

#reloadObject

Reload the Jenkins server



94
95
96
97
# File 'lib/improved_jenkins_client/system.rb', line 94

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

#restart(force = false) ⇒ Object

Restarts the Jenkins server

Parameters:

  • force (Boolean) (defaults to: false)

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



76
77
78
79
80
81
82
83
84
# File 'lib/improved_jenkins_client/system.rb', line 76

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

#restart!Object

Performs a force restart of Jenkins server



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

def restart!
  restart(true)
end

#to_sObject

Returns a string representation of System class.



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

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

#wait_for_readyObject

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



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/improved_jenkins_client/system.rb', line 115

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