Skip to content

Commit 4376d0a

Browse files
authored
feat: implement variable-substitution in trigger:include:local (#1494)
1 parent 06e05cd commit 4376d0a

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/job.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,8 +1469,9 @@ export class Job {
14691469

14701470
for (const include of this.jobData.trigger?.include ?? []) {
14711471
if (include["local"]) {
1472-
validateIncludeLocal(include["local"]);
1473-
const files = await globby(include["local"].replace(/^\//, ""), {dot: true, cwd});
1472+
const expandedInclude = Utils.expandText(include["local"], this._variables);
1473+
validateIncludeLocal(expandedInclude);
1474+
const files = await globby(expandedInclude.replace(/^\//, ""), {dot: true, cwd});
14741475
if (files.length == 0) {
14751476
throw new AssertionError({message: `Local include file \`${include["local"]}\` specified in \`.${this.name}\` cannot be found!`});
14761477
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
trigger:
3+
variables:
4+
PROJECT_DIR: "8"
5+
trigger:
6+
include:
7+
- local: $PROJECT_DIR/.gitlab-ci.yml
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
job:
3+
image: busybox
4+
script:
5+
- echo yay variable substitution works

tests/test-cases/parent-child/integration.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,21 @@ test("2 dynamic pipeline with concurrency set to 1", async () => {
115115
).join("\n");
116116
expect(filteredStdout).toEqual(expected);
117117
});
118+
119+
test("trigger:include:local should support variable substitution", async () => {
120+
const writeStreams = new WriteStreamsMock();
121+
await handler({
122+
cwd: cwd,
123+
file: ".gitlab-ci-8.yml",
124+
noColor: true,
125+
}, writeStreams);
126+
127+
const expected = ` [trigger] -> job $ echo yay variable substitution works
128+
[trigger] -> job > yay variable substitution works`;
129+
130+
const filteredStdout = writeStreams.stdoutLines.filter(f =>
131+
f.startsWith(" [trigger] -> job >")
132+
|| f.startsWith(" [trigger] -> job $")
133+
).join("\n");
134+
expect(filteredStdout).toEqual(expected);
135+
});

0 commit comments

Comments
 (0)