Skip to content

Commit 54529e3

Browse files
committed
added new variables to replace the values constant.
1 parent 45fd919 commit 54529e3

File tree

4 files changed

+53
-25
lines changed

4 files changed

+53
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"dependencies": {
4242
"@backstage/backend-common": "^0.18.3",
4343
"@backstage/errors": "^1.1.5",
44-
"@backstage/integration": "^1.4.3",
44+
"@backstage/integration": "^1.4.5",
4545
"@backstage/plugin-scaffolder-backend": "^1.13.1",
4646
"@backstage/plugin-scaffolder-node": "^0.1.1",
4747
"@backstage/types": "^1.0.2",

src/actions/run/createAzurePipeline.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const createAzurePipelineAction = (options: {
9090
description: "The location of the Azure DevOps Pipeline definition file. Defaults to /azure-pipelines.yaml",
9191
},
9292
token: {
93-
title: "Authenticatino Token",
93+
title: "Authentication Token",
9494
type: "string",
9595
description: "The token to use for authorization.",
9696
},
@@ -131,7 +131,7 @@ export const createAzurePipelineAction = (options: {
131131
// See the Azure DevOps documentation for more information about the REST API:
132132
// https://docs.microsoft.com/en-us/rest/api/azure/devops/pipelines/pipelines/create?view=azure-devops-rest-6.1
133133
await fetch(
134-
`https://dev.azure.com/${organization}/${project}/_apis/pipelines?api-version=6.1-preview.1`,
134+
`https://${host}/${organization}/${project}/_apis/pipelines?api-version=6.1-preview.1`,
135135
{
136136
method: "POST",
137137
headers: {

src/actions/run/permitAzurePipeline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const permitAzurePipelineAction = (options: {
130130
// See the Azure DevOps documentation for more information about the REST API:
131131
// https://docs.microsoft.com/en-us/rest/api/azure/devops/approvalsandchecks/pipeline-permissions/update-pipeline-permisions-for-resource?view=azure-devops-rest-7.1
132132
await fetch(
133-
`https://dev.azure.com/${organization}/${project}/_apis/pipelines/pipelinepermissions/${resourceType}/${resourceId}?api-version=7.1-preview.1`,
133+
`https://${host}/${organization}/${project}/_apis/pipelines/pipelinepermissions/${resourceType}/${resourceId}?api-version=7.1-preview.1`,
134134
{
135135
method: "PATCH",
136136
headers: {

src/actions/run/runAzurePipeline.ts

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,34 @@ import { createTemplateAction } from "@backstage/plugin-scaffolder-node";
2020

2121
import fetch from "node-fetch";
2222

23+
interface RunPipelineRequest {
24+
previewRun?: boolean;
25+
resources?: {
26+
repositories: {
27+
self: {
28+
refName: string;
29+
repositoryId?: string;
30+
repositoryType?: string;
31+
};
32+
};
33+
};
34+
templateParameters?: {
35+
[key: string]: string;
36+
};
37+
variables?: {
38+
[key: string]: string;
39+
};
40+
yamlOverrides?: string;
41+
}
42+
2343
export const runAzurePipelineAction = (options: {
2444
integrations: ScmIntegrationRegistry;
2545
}) => {
2646
const { integrations } = options;
2747

28-
async function checkPipelineStatus(organization: string, project: string, runId: number, token: string): Promise<boolean> {
48+
async function checkPipelineStatus(host: string, organization: string, project: string, runId: number, token: string): Promise<boolean> {
2949
const response = await fetch(
30-
`https://dev.azure.com/${organization}/${project}/_apis/build/builds/${runId}?api-version=6.1-preview.6`,
50+
`https://${host}/${organization}/${project}/_apis/build/builds/${runId}?api-version=6.1-preview.6`,
3151
{
3252
headers: {
3353
Authorization: `Basic ${Buffer.from(`PAT:${token}`).toString("base64")}`,
@@ -58,7 +78,8 @@ export const runAzurePipelineAction = (options: {
5878
project: string;
5979
branch?: string;
6080
token?: string;
61-
values?: object;
81+
pipelineParameters?: object;
82+
pipelineVariables?: object;
6283
}>({
6384
id: "azure:pipeline:run",
6485
schema: {
@@ -100,10 +121,15 @@ export const runAzurePipelineAction = (options: {
100121
type: "string",
101122
description: "The token to use for authorization.",
102123
},
103-
values: {
104-
title: "Values",
124+
pipelineParameters: {
125+
title: "Pipeline Parameters",
126+
type: "object",
127+
description: "The values you need as parameters on the request to start a build.",
128+
},
129+
pipelineVariables: {
130+
title: "Pipeline Variables",
105131
type: "object",
106-
description: "The values you need as parameters on the request to azure.",
132+
description: "The values you need as variables on the request to start a build.",
107133
},
108134
},
109135
},
@@ -115,7 +141,8 @@ export const runAzurePipelineAction = (options: {
115141
pipelineId,
116142
project,
117143
branch,
118-
values
144+
pipelineParameters,
145+
pipelineVariables,
119146
} = ctx.input;
120147

121148
const host = server ?? "dev.azure.com";
@@ -135,24 +162,25 @@ export const runAzurePipelineAction = (options: {
135162

136163
ctx.logger.info(`Running Azure pipeline with the ID ${pipelineId}.`);
137164

138-
let body: string;
139-
if (values) {
140-
body = JSON.stringify(values);
141-
} else {
142-
body = JSON.stringify({
143-
resources: {
144-
repositories: {
145-
self: {
146-
refName: `refs/heads/${branch ?? "main"}`,
147-
},
165+
const request: RunPipelineRequest = {
166+
resources: {
167+
repositories: {
168+
self: {
169+
refName: `refs/heads/${branch ?? "main"}`,
148170
},
149171
},
150-
});
151-
}
172+
},
173+
templateParameters: pipelineParameters as Record<string, string>,
174+
variables: pipelineVariables as Record<string, string>,
175+
yamlOverrides: "",
176+
};
177+
178+
const body = JSON.stringify(request);
179+
152180
// See the Azure DevOps documentation for more information about the REST API:
153181
// https://docs.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-6.1
154182
await fetch(
155-
`https://dev.azure.com/${organization}/${project}/_apis/pipelines/${pipelineId}/runs?api-version=6.1-preview.1`,
183+
`https://${host}/${organization}/${project}/_apis/pipelines/${pipelineId}/runs?api-version=6.1-preview.1`,
156184
{
157185
method: "POST",
158186
headers: {
@@ -178,7 +206,7 @@ export const runAzurePipelineAction = (options: {
178206
const pipelineRunId = json.id;
179207

180208
// Poll the pipeline status until it completes.
181-
return checkPipelineStatus(organization, project, pipelineRunId, token);
209+
return checkPipelineStatus(host, organization, project, pipelineRunId, token);
182210
})
183211
.then((success) => {
184212
if (success) {

0 commit comments

Comments
 (0)