The Jenkins Last Commit widget periodically fetches SCM change information from a Jenkins instance for a specified list of jobs.
This allows you to have multiple widgets simultaneously (monitoing separate jobs for changes).
Calls are made to the Jenkins API to retrieve the changeset object in a JSON form. This JSON object contains various pieces of information about the last commit made for the Jenkins job.
This widget uses the Jenkins Build as a base, and extends the native List Dashing widget.
The widget has been tested with Git and Perforce changesets on Jenkins. The widget has also been tested with secure Jenkins instances (SSL / HTTPS).
Place the following files in your widgets/jenkinslastcommit
folder:
jenkinslastcommit.coffee
jenkinslastcommit.html
jenkinslastcommit.scss
Place the following file in your jobs/
folder:
jenkins-last-commit.rb
There are a few parameters that must be set up before using this widget with your Jenkins instance.
In the jenkins-last-commit.rb file, modify the following parameters according to your needs:
Parameter | Meaning |
---|---|
JENKINS_URI |
Jenkins base URL |
JENKINS_USING_SSL |
true if using SSL (HTTPS), false if not using SSL (HTTP) |
JENKINS_AUTH |
Jenkins user credentials (required for HTTPS implementations) |
$jenkins_jobs_to_be_monitored |
This is a hash containing multiple key-value pairs, where: key = Jenkins job to monitor, Value = dashboard event ID |
To add this widget to your dashboard, add the following to your [Dashboard-filename].erb file:
<!-- widget with event ID: jenkins-last-commit-1 -->
<li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
<div data-id="jenkins-last-commit-1" data-view="Jenkinslastcommit" data-unordered="true" data-title="Last commit (job 1)" ></div>
</li>
<!-- widget with event ID: jenkins-last-commit-2 -->
<li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
<div data-id="jenkins-last-commit-2" data-view="Jenkinslastcommit" data-unordered="true" data-title="Last commit (job 2)" ></div>
</li>
Jenkins provides slightly different JSON structures for the changeSet objects between Git and Perforce - there may be differences in the JSON structure when used with your SCM.
{
"changeSet": {
"items": [
{
"affectedPaths": [
"..../XXX.cpp",
".../YYY.cpp"
],
"author": {
"absoluteUrl": "http://JENKINS/user/USERNAME",
"description": null,
"fullName": "USERNAME",
"id": "USERNAME",
"property": [
{ },{ },{ },{ },{ },{ },
]
},
"commitId": null,
"msg": "Commit message",
"timestamp": -1,
"changeNumber": "20548",
"changeTime": "2014-02-27 19:24:52"
}
],
"kind": null
}
}
{
"changeSet"=>{
"items"=>[
{
"affectedPaths"=>[
".../XXX.cpp",
".../YYY.cpp"
],
"commitId"=>"4429435e1eb546b745775ea957ede9f2983df6b9",
"timestamp"=>1393760162000,
"author"=>{
"absoluteUrl"=>"http://JENKINS/USERNAME",
"description"=>nil,
"fullName"=>"USERNAME",
"id"=>"USERNAME",
"property"=>[ {}, {}, {}, {}, {}, {}
]
},
"comment"=>"Commit message text",
"date"=>"2014-03-02 13:36:02 +0200",
"id"=>"4429435e1eb546b745775ea957ede9f2983df6b9",
"msg"=>"Commit message text",
"paths"=>[
{
"editType"=>"edit",
"file"=>".../XXX.cpp"
},
{
"editType"=>"edit",
"file"=>".../YYY.cpp"
}
]
}
],
"kind"=>"git"
}
}
It would be nice if we could monitor more then one job, like it is in jenkins ci widget ;)