fix: allow gitlab pipeline triggers to include variables
Signed-off-by: John Redwood <john.r.k.redwood@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend-module-gitlab': minor
|
||||
---
|
||||
|
||||
Fixed trigger pipeline accepting input variables
|
||||
@@ -211,6 +211,7 @@ export const createTriggerGitlabPipelineAction: (options: {
|
||||
projectId: number;
|
||||
tokenDescription: string;
|
||||
token?: string | undefined;
|
||||
variables?: Record<string, string> | undefined;
|
||||
},
|
||||
{
|
||||
pipelineUrl: string;
|
||||
|
||||
@@ -33,6 +33,7 @@ export const examples: TemplateExample[] = [
|
||||
'This is the text that will appear in the pipeline token',
|
||||
token: 'glpt-xxxxxxxxxxxx',
|
||||
branch: 'main',
|
||||
variables: { var_one: 'one', var_two: 'two' },
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -101,6 +101,7 @@ describe('gitlab:pipeline:trigger', () => {
|
||||
123,
|
||||
'main',
|
||||
'glptt-abcdef',
|
||||
{ variables: undefined },
|
||||
);
|
||||
|
||||
expect(mockGitlabClient.PipelineTriggerTokens.remove).toHaveBeenCalledWith(
|
||||
@@ -189,6 +190,7 @@ describe('gitlab:pipeline:trigger', () => {
|
||||
123,
|
||||
'main',
|
||||
'glptt-abcdef',
|
||||
{ variables: undefined },
|
||||
);
|
||||
|
||||
expect(mockGitlabClient.PipelineTriggerTokens.remove).toHaveBeenCalledWith(
|
||||
@@ -196,6 +198,7 @@ describe('gitlab:pipeline:trigger', () => {
|
||||
42,
|
||||
);
|
||||
});
|
||||
|
||||
it('should clean up pipeline token on failure', async () => {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
@@ -232,4 +235,30 @@ describe('gitlab:pipeline:trigger', () => {
|
||||
42,
|
||||
);
|
||||
});
|
||||
|
||||
it('should succeed trigger and pass variables', async () => {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'gitlab.com?repo=repo&owner=owner',
|
||||
projectId: 123,
|
||||
tokenDescription: 'My cool pipeline token',
|
||||
branch: 'main',
|
||||
variables: { var_one: 'val1', var_two: 'val2' },
|
||||
},
|
||||
workspacePath: 'seen2much',
|
||||
});
|
||||
|
||||
await expect(
|
||||
action.handler({
|
||||
...mockContext,
|
||||
}),
|
||||
).rejects.toThrow('Failed to trigger pipeline');
|
||||
|
||||
expect(mockGitlabClient.PipelineTriggerTokens.trigger).toHaveBeenCalledWith(
|
||||
123,
|
||||
'main',
|
||||
'glptt-abcdef',
|
||||
{ variables: { var_one: 'val1', var_two: 'val2' } },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -30,6 +30,12 @@ const pipelineInputProperties = z.object({
|
||||
projectId: z.number().describe('Project Id'),
|
||||
tokenDescription: z.string().describe('Pipeline token description'),
|
||||
branch: z.string().describe('Project branch'),
|
||||
variables: z
|
||||
.record(z.string(), z.string())
|
||||
.optional()
|
||||
.describe(
|
||||
'A object/record of key-valued strings containing the pipeline variables.',
|
||||
),
|
||||
});
|
||||
|
||||
const pipelineOutputProperties = z.object({
|
||||
@@ -57,7 +63,7 @@ export const createTriggerGitlabPipelineAction = (options: {
|
||||
async handler(ctx) {
|
||||
let pipelineTokenResponse: PipelineTriggerTokenSchema | null = null;
|
||||
|
||||
const { repoUrl, projectId, tokenDescription, token, branch } =
|
||||
const { repoUrl, projectId, tokenDescription, token, branch, variables } =
|
||||
commonGitlabConfig.merge(pipelineInputProperties).parse(ctx.input);
|
||||
|
||||
const { host } = parseRepoUrl(repoUrl, integrations);
|
||||
@@ -84,6 +90,7 @@ export const createTriggerGitlabPipelineAction = (options: {
|
||||
projectId,
|
||||
branch,
|
||||
pipelineTokenResponse.token,
|
||||
{ variables },
|
||||
)) as ExpandedPipelineSchema;
|
||||
|
||||
if (!pipelineTriggerResponse.id) {
|
||||
|
||||
Reference in New Issue
Block a user