Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit 2def900

Browse files
committed
Merge pull request #485 from chriskchew/jenkins-describe
Added a "Jenkins describe" action
2 parents 9fd9804 + c95ed09 commit 2def900

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/scripts/jenkins.coffee

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# hubot jenkins build <job> - builds the specified Jenkins job
1313
# hubot jenkins build <job>, <params> - builds the specified Jenkins job with parameters as key=value&key2=value2
1414
# hubot jenkins list - lists Jenkins jobs
15+
# hubot jenkins describe <job> - Describes the specified Jenkins job
16+
1517
#
1618
# Author:
1719
# dougcole
@@ -40,6 +42,57 @@ jenkinsBuild = (msg) ->
4042
else
4143
msg.send "Jenkins says: #{body}"
4244

45+
jenkinsDescribe = (msg) ->
46+
url = process.env.HUBOT_JENKINS_URL
47+
job = msg.match[1]
48+
49+
path = "#{url}/job/#{job}/api/json"
50+
51+
req = msg.http(path)
52+
53+
if process.env.HUBOT_JENKINS_AUTH
54+
auth = new Buffer(process.env.HUBOT_JENKINS_AUTH).toString('base64')
55+
req.headers Authorization: "Basic #{auth}"
56+
57+
req.header('Content-Length', 0)
58+
req.get() (err, res, body) ->
59+
if err
60+
msg.send "Jenkins says: #{err}"
61+
else
62+
response = ""
63+
try
64+
content = JSON.parse(body)
65+
response += "JOB: #{content.displayName}\n"
66+
67+
if content.description
68+
response += "DESCRIPTION: #{content.description}\n"
69+
70+
response += "ENABLED: #{content.buildable}\n"
71+
response += "STATUS: #{content.color}\n"
72+
73+
tmpReport = ""
74+
if content.healthReport.length > 0
75+
for report in content.healthReport
76+
tmpReport += "\n #{report.description}"
77+
else
78+
tmpReport = " unknown"
79+
response += "HEALTH: #{tmpReport}\n"
80+
81+
parameters = ""
82+
for item in content.actions
83+
if item.parameterDefinitions
84+
for param in item.parameterDefinitions
85+
tmpDescription = if param.description then " - #{param.description} " else ""
86+
tmpDefault = if param.defaultParameterValue then " (default=#{param.defaultParameterValue.value})" else ""
87+
parameters += "\n #{param.name}#{tmpDescription}#{tmpDefault}"
88+
89+
if parameters != ""
90+
response += "PARAMETERS: #{parameters}\n"
91+
92+
msg.send response
93+
catch error
94+
msg.send error
95+
4396
jenkinsList = (msg) ->
4497
url = process.env.HUBOT_JENKINS_URL
4598
job = msg.match[1]
@@ -70,6 +123,9 @@ module.exports = (robot) ->
70123
robot.respond /jenkins list/i, (msg) ->
71124
jenkinsList(msg)
72125

126+
robot.respond /jenkins describe ([\w\.\-_]+)/i, (msg) ->
127+
jenkinsDescribe(msg)
128+
73129
robot.jenkins = {
74130
list: jenkinsList,
75131
build: jenkinsBuild

0 commit comments

Comments
 (0)