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

#initialize(client) ⇒ System

Initializes a new System object.

Parameters:

  • client (Object)

    a reference to Client



36
37
38
# File 'lib/jenkins_api_client/system.rb', line 36

def initialize(client)
  @client = client
end

Instance Method Details

#cancel_quiet_downObject

Cancels the quiet doen request sent to the server.



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

def cancel_quiet_down
  @client.api_post_request("/cancelQuietDown")
end

#quiet_downObject

Sends a quiet down request to the server.



48
49
50
# File 'lib/jenkins_api_client/system.rb', line 48

def quiet_down
  @client.api_post_request("/quietDown")
end

#reloadObject

Reload the Jenkins server



73
74
75
# File 'lib/jenkins_api_client/system.rb', line 73

def reload
  @client.api_post_request("/reload")
end

#restart(force = false) ⇒ Object

Restarts the Jenkins server

Parameters:

  • force (Bool) (defaults to: false)

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



63
64
65
66
67
68
69
# File 'lib/jenkins_api_client/system.rb', line 63

def restart(force = false)
  if force
    @client.api_post_request("/restart")
  else
    @client.api_post_request("/safeRestart")
  end
end

#to_sObject

Returns a string representation of System class.



42
43
44
# File 'lib/jenkins_api_client/system.rb', line 42

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

#wait_for_readyObject

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/jenkins_api_client/system.rb', line 80

def wait_for_ready
  Timeout::timeout(@client.timeout) do
    while true do
      response = @client.get_root
      puts "[INFO] Waiting for jenkins to restart..." if @client.debug
      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