This repository has been archived by the owner on Feb 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marek Sierociński
committed
Aug 22, 2019
0 parents
commit 224e277
Showing
8 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# EditorConfig | ||
# | ||
# This file helps maintain consistent coding styles for multiple developers | ||
# working on the same project across various editors and IDEs | ||
# | ||
# https://EditorConfig.org | ||
# | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{json, html}] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# IDE | ||
/.idea | ||
|
||
# Node | ||
/node_modules | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.idea | ||
/.editorconfig | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ISC License | ||
|
||
Copyright (c) 2019, Marek Sierociński | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# dashbi-data-provider-jenkins-build | ||
|
||
Dashbi data provider that fetches last build for given Jenkins job. | ||
|
||
## Usage | ||
|
||
### Install | ||
|
||
```sh | ||
npm install --save dashbi-data-provider-jenkins-build | ||
``` | ||
|
||
### Register | ||
|
||
Dashbi should detect and auto-register data provider. | ||
|
||
### Config Source | ||
|
||
You need to provide to params: | ||
|
||
* `jenkinsUrl` | ||
* `jobPath` | ||
|
||
### Example | ||
|
||
Let's say that your Jenkins Job URL is `https://myjenkins.example.org/job/Hello/`. | ||
Your widget configuration could look like this: | ||
|
||
```js | ||
dashbiLayout.addWidget({ | ||
name: 'jenkins-build-status', | ||
title: 'My Jenkins Job', | ||
source: { | ||
name: 'jenkins-build', | ||
params: { | ||
jenkinsUrl: 'https://myjenkins.example.org', | ||
jobPath: 'job/Hello' | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
### Widget | ||
|
||
Widget created to display build status is [jenkins-build-status](https://github.com/marverix/dashbi-widget-jenkins-build-status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
const axios = require('axios'); | ||
const Worker = require('dashbi-worker'); | ||
|
||
/** | ||
* Strip wrapping slashes | ||
* @param {string} str | ||
*/ | ||
function stripWrappingSlashes (str) { | ||
return str.replace(/^\/|\/$/g, ''); | ||
} | ||
|
||
/** | ||
* Get last build | ||
*/ | ||
function getLastBuild () { | ||
let that = this; | ||
axios.get(`${stripWrappingSlashes(that.config.jenkinsUrl)}/${stripWrappingSlashes(that.config.jobPath)}/lastBuild/api/json`, { | ||
timeout: 2 * Date.SECOND | ||
}) | ||
.then(function (res) { | ||
that.storeState('id', res.data.id); | ||
that.storeState('result', res.data.result); | ||
that.storeState('duration', res.data.duration); | ||
}) | ||
.catch(function (err) { | ||
// Support error? | ||
}); | ||
} | ||
|
||
// Create worker | ||
const worker = new Worker({ | ||
jenkinsUrl: '', | ||
jobPath: '' | ||
}); | ||
|
||
// Add checks | ||
worker.addCheck(getLastBuild, Math.floor(5 * Date.SECOND + Math.rand() * Date.SECOND) ); | ||
worker.sendOnChange(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "dashbi-data-provider-jenkins-build", | ||
"version": "0.1.0", | ||
"description": "Dashbi data provider that fetches last build for given Jenkins job", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"dashbi", | ||
"dashbi-data-provider", | ||
"jenkins", | ||
"jenkins-build", | ||
"jenkins-job" | ||
], | ||
"author": "Marek Sierociński <mareksierocinski@gmail.com>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^0.19.0", | ||
"dashbi-worker": "^0.1.0" | ||
} | ||
} |