Support rebuilding a build

Note that like the previous implementation, this actually triggers a build of the project, not a re-build of a given build.

Signed-off-by: Andrew Shirley <andrew.shirley@sainsburys.co.uk>
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
Andrew Shirley
2021-06-02 18:55:25 +01:00
committed by blam
parent 64b279a55b
commit 79593909c9
5 changed files with 67 additions and 26 deletions
+32 -3
View File
@@ -52,8 +52,10 @@ const jobTreeSpec = `actions[*],
${lastBuildTreeSpec}
jobs{0,1},
name,
fullName,
displayName,
fullDisplayName`;
fullDisplayName,
inQueue`;
const jobsTreeSpec = `jobs[
${jobTreeSpec}
@@ -67,8 +69,7 @@ export interface RouterOptions {
export async function createRouter(
options: RouterOptions,
): Promise<express.Router> {
// @ts-ignore keeping unused logger for future use
const { logger, jenkinsInfoProvider } = options;
const { jenkinsInfoProvider } = options;
const router = Router();
router.use(express.json());
@@ -169,6 +170,34 @@ export async function createRouter(
},
);
router.post(
'/v1/entity/:namespace/:kind/:name/job/:jobName/:buildNumber::rebuild',
async (request, response) => {
const { namespace, kind, name, jobName } = request.params;
const jenkinsInfo = await jenkinsInfoProvider.getInstance({
entityRef: {
kind,
namespace,
name,
},
jobName,
});
const client = await getClient(jenkinsInfo);
// looks like the current SDK only supports triggering a new build
// can't see any support for replay (re-running the specific build with the same SCM info)
// Note Jenkins itself has concepts of rebuild and replay on a job.
// The latter should be possible to trigger with a POST to /replay/rebuild
await client.job.build(jobName);
// TODO: return the buildNumber which was started.
response.send({});
},
);
router.use(errorHandler());
return router;
}