Skip to content

Commit 2195c19

Browse files
committed
Added integration test for CI_PROJECT_DIR (predefined variable)
1 parent 88b848c commit 2195c19

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/job.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,20 @@ export class Job {
7979
this.environment = typeof jobData.environment === "string" ? {name: jobData.environment} : jobData.environment;
8080
this.cache = jobData.cache || null;
8181

82+
let CI_PROJECT_DIR = `${this.cwd}`;
83+
if (this.imageName) {
84+
CI_PROJECT_DIR = `/builds/${this.safeJobName}`;
85+
} else if (this.shellIsolation) {
86+
CI_PROJECT_DIR = `${this.cwd}/.gitlab-ci-local/builds/${this.safeJobName}`;
87+
}
88+
8289
const predefinedVariables = {
8390
GITLAB_USER_LOGIN: gitData.user["GITLAB_USER_LOGIN"],
8491
GITLAB_USER_EMAIL: gitData.user["GITLAB_USER_EMAIL"],
8592
GITLAB_USER_NAME: gitData.user["GITLAB_USER_NAME"],
8693
CI_COMMIT_SHORT_SHA: gitData.commit.SHORT_SHA, // Changes
8794
CI_COMMIT_SHA: gitData.commit.SHA,
88-
CI_PROJECT_DIR: this.imageName ? `/builds/${this.safeJobName}` : `${this.cwd}`,
95+
CI_PROJECT_DIR,
8996
CI_PROJECT_NAME: gitData.remote.project,
9097
CI_PROJECT_TITLE: `${camelCase(gitData.remote.project)}`,
9198
CI_PROJECT_PATH: gitData.CI_PROJECT_PATH,

tests/test-cases/predefined-variables/.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ test-job:
44
- echo ${CI_PROJECT_NAME}
55
- echo ${CI_PROJECT_PATH_SLUG}
66
- echo ${CI_PROJECT_NAMESPACE}
7+
- echo ${CI_PROJECT_DIR}

tests/test-cases/predefined-variables/integration.predefined-variables.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,18 @@ test("predefined-variables <test-job>", async () => {
1212
expect(writeStreams.stdoutLines[3]).toEqual(chalk`{blueBright test-job} {greenBright >} predefined-variables`);
1313
expect(writeStreams.stdoutLines[5]).toEqual(chalk`{blueBright test-job} {greenBright >} gcl-predefined-variables`);
1414
expect(writeStreams.stdoutLines[7]).toEqual(chalk`{blueBright test-job} {greenBright >} gcl`);
15+
expect(writeStreams.stdoutLines[9]).toEqual(chalk`{blueBright test-job} {greenBright >} tests/test-cases/predefined-variables`);
16+
expect(writeStreams.stderrLines).toEqual([]);
17+
});
18+
19+
test("predefined-variables <test-job> --shell-isolation", async () => {
20+
const writeStreams = new MockWriteStreams();
21+
await handler({
22+
cwd: "tests/test-cases/predefined-variables",
23+
jobs: ["test-job"],
24+
shellIsolation: true,
25+
}, writeStreams);
26+
27+
expect(writeStreams.stdoutLines[9]).toEqual(chalk`{blueBright test-job} {greenBright >} tests/test-cases/predefined-variables/.gitlab-ci-local/builds/test-job`);
1528
expect(writeStreams.stderrLines).toEqual([]);
1629
});

0 commit comments

Comments
 (0)