In this JavaScript example, build durations are calculated and written out to the JavaScript console.
This sample uses version 2 of the Export API, available since Develocity 2021.2.
In order to use it with older Develocity versions, please modify the following line in index.js
:
this.baseUrl = `${this.develocityServerUrl}/build-export/v2`
must be changed to
this.baseUrl = `${this.develocityServerUrl}/build-export/v1`
To run this sample:
- Install node.js.
- Run
npm install
within this directory.
We recommend using the Bearer token authentication which has been available since Develocity 2021.1.
- Create a Develocity access key for a user with the
Export API
role as described in the Export API Access Control documentation. - Set an environment variable locally:
EXPORT_API_ACCESS_KEY
to match the newly created Develocity access key.
Non-SAML users can authenticate via basic auth.
- Create a Develocity user with the
Export API
role as described in the Export API Access Control documentation. - Set two environment variables locally:
EXPORT_API_USER
EXPORT_API_PASSWORD
to match the newly created Export API user credentials.
Run npm start https://develocity.example.com
replacing develocity.example.com
with your Develocity server URL.
Alternatively to setting environment variables, credentials can be passed to the Node process by running:
EXPORT_API_ACCESS_KEY=<KEYVALUE> npm start https://develocity.example.com
replacing <KEYVALUE>
with the access key or instead using EXPORT_API_USER
and EXPORT_API_PASSWORD
in the case of Basic authentication.
Now start publishing builds to your Develocity instance and watch their build durations get written to the console.
If using the script in an HTML page instead of a Node application, remove the first line of index.js:
const EventSourcePolyfill = require('eventsource');
.
And ensure the EventSourcePolyfill
module is loaded in the page before running the example script by adding:
<script type="text/javascript" src="https://unpkg.com/[email protected]/example/eventsource-polyfill.js"></script>
to the <head>
of the HTML page.