Skip to content

Commit e4d162a

Browse files
authored
Merge pull request #188 from nikolapeja6/users/nikolapeja6/issue-72
Option to specify build parameters in build_run_build tool (Issue #72)
2 parents a40ae28 + a296c46 commit e4d162a

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

src/tools/builds.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,42 @@ function configureBuildTools(
271271
project: z.string().describe("Project ID or name to run the build in"),
272272
definitionId: z.number().describe("ID of the build definition to run"),
273273
sourceBranch: z.string().optional().describe("Source branch to run the build from. If not provided, the default branch will be used."),
274+
parameters: z.record(z.string(), z.string()).optional().describe("Custom build parameters as key-value pairs"),
274275
},
275-
async ({ project, definitionId, sourceBranch }) => {
276+
async ({ project, definitionId, sourceBranch, parameters }) => {
276277
const connection = await connectionProvider();
277278
const buildApi = await connection.getBuildApi();
278-
const build = await buildApi.queueBuild({ definition: { id: definitionId }, sourceBranch }, project);
279+
const pipelinesApi = await connection.getPipelinesApi();
280+
const definition = await buildApi.getDefinition(project, definitionId);
281+
const runRequest = {
282+
resources: {
283+
repositories: {
284+
self: {
285+
refName:
286+
sourceBranch ||
287+
definition.repository?.defaultBranch ||
288+
"refs/heads/main",
289+
},
290+
},
291+
},
292+
templateParameters: parameters,
293+
};
294+
295+
const pipelineRun = await pipelinesApi.runPipeline(
296+
runRequest,
297+
project,
298+
definitionId
299+
);
300+
const queuedBuild = { id: pipelineRun.id };
301+
const buildId = queuedBuild.id;
302+
if (buildId === undefined) {
303+
throw new Error("Failed to get build ID from pipeline run");
304+
}
279305

306+
const buildReport = await buildApi.getBuildReport(project, buildId);
280307
return {
281-
content: [{ type: "text", text: JSON.stringify(build, null, 2) }],
282-
};
308+
content: [{ type: "text", text: JSON.stringify(buildReport, null, 2) }],
309+
};
283310
}
284311
);
285312

0 commit comments

Comments
 (0)