Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getBuildStages API #784

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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