Skip to content

Commit

Permalink
Add getBuildStages API
Browse files Browse the repository at this point in the history
related: adoptium#777

Signed-off-by: Lan Xia <Lan_Xia@ca.ibm.com>
  • Loading branch information
llxia committed Mar 24, 2023
1 parent 7a5789a commit 2280a8f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
36 changes: 36 additions & 0 deletions TestResultSummaryService/JenkinsApiQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const got = require('got');
const url = require('url');
const { logger, addCredential } = require('./Utils');
const ArgParser = require('./ArgParser');

class JenkinsApiQuery {
constructor(options) {
this.credentails = ArgParser.getConfig();
const build = options.build || 'lastBuild';
this.url =
addCredential(this.credentails, options.baseUrl) +
'/job/' +
options.job +
'/' +
build +
'/';
}

async getBuildStages() {
const wfapi = this.url + 'wfapi/describe';
logger.debug(
`JenkinsApiQuery: getStages(): [CIServerRequest] url: ${wfapi}`
);
const response = await got.get(wfapi, {
followRedirect: true,
timeout: 1 * 60 * 1000,
});
if (response.body.length === 0) {
return '';
} else {
return response.body;
}
}
}

module.exports = JenkinsApiQuery;
25 changes: 25 additions & 0 deletions TestResultSummaryService/routes/getBuildStages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const JenkinsApiQuery = require('../JenkinsApiQuery');

/**
* getBuildStages query Jenkins via REST API
*
* @route GET /api/getBuildStages
* @param {string} url Required. Jenkins server url (it is used to identify the build).
* @param {string} buildName Required.
* @param {string} buildNum Required.
*/

module.exports = async (req, res) => {
const { url, buildName, buildNum } = req.query;
try {
const jenkinsApiQuery = new JenkinsApiQuery({
baseUrl: url,
job: buildName,
build: parseInt(buildNum, 10),
});
const output = await jenkinsApiQuery.getBuildStages();
res.send(output);
} catch (e) {
res.send({ result: e.toString() });
}
};
1 change: 1 addition & 0 deletions TestResultSummaryService/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ app.get('/getAuditLogs', wrap(require('./getAuditLogs')));
app.get('/getBenchmarkMetricProps', wrap(require('./getBenchmarkMetricProps')));
app.get('/getBuildHistory', wrap(require('./getBuildHistory')));
app.get('/getBuildList', wrap(require('./getBuildList')));
app.get('/getBuildStages', wrap(require('./getBuildStages')));
app.get('/getChildBuilds', wrap(require('./getChildBuilds')));
app.get('/getDashboardBuildInfo', wrap(require('./getDashboardBuildInfo')));
app.get('/getData', wrap(require('./getData')));
Expand Down

0 comments on commit 2280a8f

Please sign in to comment.