Class: Lita::Handlers::JenkinsClient::JobAction

Inherits:
Action show all
Defined in:
lib/lita/handlers/jenkins_client/job_action.rb

Constant Summary

Constants inherited from Lita::Handlers::JenkinsClient

CONFIGS

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commandsObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lita/handlers/jenkins_client/job_action.rb', line 15

def commands
  super.merge({
    all: Command.new(name: 'all', matcher: 'all', help: 'list all jobs.'),
    list: Command.new(name: 'list', matcher: 'list', help: 'list jobs matching pattern.', usage: 'list [filter]'),
    list_by_status: Command.new(name: 'list_by_status', matcher: 'list_by_status', help: 'list jobs with certain status.', usage: 'list_by_status [success/failure]'),
    status: Command.new(name: 'status', matcher: 'status', help: 'print job status.', usage: 'status [job name]'),
    build: Command.new(name: 'build', matcher: 'build', help: "build job, #{BuildParam.print_supported_types}", usage: 'build [job name] [param_key:param_value]'),
    params: Command.new(name: 'params', matcher: 'params', help: 'obtain the build parameters of a job.', usage: 'params [job_name]'),
    exists?: Command.new(name: 'exists?', matcher: 'exists', help: 'check if a job exists', usage: 'exists [job name]'),
  })
end

.route_prefixObject



11
12
13
# File 'lib/lita/handlers/jenkins_client/job_action.rb', line 11

def route_prefix
  super + ["job"]
end

Instance Method Details

#all(res) ⇒ Object



28
29
30
31
32
# File 'lib/lita/handlers/jenkins_client/job_action.rb', line 28

def all(res)
  res.reply api_exec {
    client.job.list_all.inspect
  }
end

#build(res) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/lita/handlers/jenkins_client/job_action.rb', line 52

def build(res)
  if res.args.length < 3
    res.reply 'please provide a job name'
    return
  end

  job_name = res.args[2]
  if client.job.exists?(job_name) == false
    res.reply "job #{job_name} not exists" 
    return 
  end
  hash_args = key_value_pair(res.args.slice(3...res.args.length))
  if hash_args.empty? 
    res.reply api_exec { 
      print_build_status(client.job.build(job_name))
    }
    return 
  end

  begin
    params = parse_build_params(hash_args, client.job.get_build_params(job_name))
    res.reply api_exec { 
      print_build_status(client.job.build(job_name, params))
    }
  rescue ArgumentError => e
    res.reply "Error: #{e.message}"
  end
end

#delete(res) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/lita/handlers/jenkins_client/job_action.rb', line 81

def delete(res)
  if res.args.length < 3 
    res.reply 'please provide a job name'
    return
  end

  res.reply api_exec { client.job.delete(res.args[2]).inspect }
end

#exists?(res) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
# File 'lib/lita/handlers/jenkins_client/job_action.rb', line 99

def exists?(res)
  if res.args.length < 3
    res.reply 'please provide a job name'
    return
  end

  res.reply api_exec { client.job.exists?(res.args[2]).inspect }
end

#list(res) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/lita/handlers/jenkins_client/job_action.rb', line 34

def list(res)
  if res.args.length < 3
    res.reply 'please provide a search condition'
    return
  end

  res.reply api_exec { client.job.list(res.args[2]) }
end

#list_by_status(res) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/lita/handlers/jenkins_client/job_action.rb', line 43

def list_by_status(res)
  if res.args.length < 3
    res.reply 'please provide a status ( SUCCESS, FAILURE )'
    return
  end
  
  res.reply api_exec { client.job.list_by_status(res.args[2]) }
end

#params(res) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/lita/handlers/jenkins_client/job_action.rb', line 108

def params(res)
  if res.args.length < 3 
    res.reply 'please provide a job name'
    return
  end

  res.reply api_exec { client.job.get_build_params(res.args[2]).inspect }
end

#status(res) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/lita/handlers/jenkins_client/job_action.rb', line 90

def status(res)
  if res.args.length < 3 
    res.reply 'please provide a job name'
    return
  end

  res.reply api_exec { client.job.get_current_build_status(res.args[2]).inspect }
end