@@ -20,14 +20,34 @@ import { createTemplateAction } from "@backstage/plugin-scaffolder-node";
20
20
21
21
import fetch from "node-fetch" ;
22
22
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
+
23
43
export const runAzurePipelineAction = ( options : {
24
44
integrations : ScmIntegrationRegistry ;
25
45
} ) => {
26
46
const { integrations } = options ;
27
47
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 > {
29
49
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` ,
31
51
{
32
52
headers : {
33
53
Authorization : `Basic ${ Buffer . from ( `PAT:${ token } ` ) . toString ( "base64" ) } ` ,
@@ -58,7 +78,8 @@ export const runAzurePipelineAction = (options: {
58
78
project : string ;
59
79
branch ?: string ;
60
80
token ?: string ;
61
- values ?: object ;
81
+ pipelineParameters ?: object ;
82
+ pipelineVariables ?: object ;
62
83
} > ( {
63
84
id : "azure:pipeline:run" ,
64
85
schema : {
@@ -100,10 +121,15 @@ export const runAzurePipelineAction = (options: {
100
121
type : "string" ,
101
122
description : "The token to use for authorization." ,
102
123
} ,
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" ,
105
131
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 ." ,
107
133
} ,
108
134
} ,
109
135
} ,
@@ -115,7 +141,8 @@ export const runAzurePipelineAction = (options: {
115
141
pipelineId,
116
142
project,
117
143
branch,
118
- values
144
+ pipelineParameters,
145
+ pipelineVariables,
119
146
} = ctx . input ;
120
147
121
148
const host = server ?? "dev.azure.com" ;
@@ -135,24 +162,25 @@ export const runAzurePipelineAction = (options: {
135
162
136
163
ctx . logger . info ( `Running Azure pipeline with the ID ${ pipelineId } .` ) ;
137
164
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" } ` ,
148
170
} ,
149
171
} ,
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
+
152
180
// See the Azure DevOps documentation for more information about the REST API:
153
181
// https://docs.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-6.1
154
182
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` ,
156
184
{
157
185
method : "POST" ,
158
186
headers : {
@@ -178,7 +206,7 @@ export const runAzurePipelineAction = (options: {
178
206
const pipelineRunId = json . id ;
179
207
180
208
// Poll the pipeline status until it completes.
181
- return checkPipelineStatus ( organization , project , pipelineRunId , token ) ;
209
+ return checkPipelineStatus ( host , organization , project , pipelineRunId , token ) ;
182
210
} )
183
211
. then ( ( success ) => {
184
212
if ( success ) {
0 commit comments