forked from adoptium/aqa-test-tools
-
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.
related: adoptium#777 Signed-off-by: Lan Xia <Lan_Xia@ca.ibm.com>
- Loading branch information
Showing
3 changed files
with
62 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,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; |
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,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() }); | ||
} | ||
}; |
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