Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Sierociński committed Aug 22, 2019
0 parents commit 224e277
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# IDE
/.idea

# Node
/node_modules
*.tgz
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.idea
/.editorconfig
*.tgz
15 changes: 15 additions & 0 deletions LICENSE
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.
45 changes: 45 additions & 0 deletions README.md
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)
40 changes: 40 additions & 0 deletions index.js
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();
56 changes: 56 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
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"
}
}

0 comments on commit 224e277

Please sign in to comment.