Add taskID and tests
Signed-off-by: Fabio Vincenzi <fabio.vincenzi2001@gmail.com>
This commit is contained in:
@@ -684,6 +684,34 @@ describe('NunjucksWorkflowRunner', () => {
|
||||
|
||||
expect(output.foo).toEqual('BACKSTAGE');
|
||||
});
|
||||
|
||||
it('should include task ID in the templated context', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [
|
||||
{
|
||||
id: 'test',
|
||||
name: 'name',
|
||||
action: 'jest-mock-action',
|
||||
input: {
|
||||
values: {
|
||||
taskId: '${{context.task.id}}',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
output: {},
|
||||
parameters: {},
|
||||
});
|
||||
|
||||
await runner.execute(task);
|
||||
|
||||
expect(fakeActionHandler).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
input: { values: { taskId: 'test-workspace' } },
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('redactions', () => {
|
||||
|
||||
@@ -80,6 +80,11 @@ type TemplateContext = {
|
||||
ref?: string;
|
||||
};
|
||||
each?: JsonValue;
|
||||
context: {
|
||||
task: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
type CheckpointState =
|
||||
@@ -480,11 +485,15 @@ export class NunjucksWorkflowRunner implements WorkflowRunner {
|
||||
|
||||
const taskTrack = await this.tracker.taskStart(task);
|
||||
await fs.ensureDir(workspacePath);
|
||||
|
||||
const context: TemplateContext = {
|
||||
parameters: task.spec.parameters,
|
||||
steps: {},
|
||||
user: task.spec.user,
|
||||
context: {
|
||||
task: {
|
||||
id: taskId,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [decision]: PolicyDecision[] =
|
||||
|
||||
Reference in New Issue
Block a user