Skip to content

Commit 6d8152d

Browse files
authored
Merge pull request #100 from firecow/image-entrypoint-echo-variable
Add environment variables to docker create
2 parents 2dae0c9 + 106de14 commit 6d8152d

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/job.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,16 @@ export class Job {
309309

310310
let dockerCmd = ``;
311311
if (privileged) {
312-
dockerCmd += `docker create --privileged -u 0:0 -i ${this.image} `;
312+
dockerCmd += `docker create --privileged -u 0:0 -i `;
313313
} else {
314-
dockerCmd += `docker create -u 0:0 -i ${this.image} `;
314+
dockerCmd += `docker create -u 0:0 -i `;
315315
}
316-
dockerCmd += `sh -c "\n`
316+
317+
for (const [key, value] of Object.entries(this.expandedVariables)) {
318+
dockerCmd += `-e ${key}="${String(value).trim()}" `
319+
}
320+
321+
dockerCmd += `${this.image} sh -c "\n`
317322
dockerCmd += `if [ -x /usr/local/bin/bash ]; then\n`
318323
dockerCmd += `\texec /usr/local/bin/bash \n`;
319324
dockerCmd += `elif [ -x /usr/bin/bash ]; then\n`;
@@ -332,6 +337,7 @@ export class Job {
332337
dockerCmd += `\techo shell not found\n`;
333338
dockerCmd += `\texit 1\n`;
334339
dockerCmd += `fi\n"`
340+
335341
const {stdout: containerId} = await Utils.spawn(dockerCmd, this.cwd, {...process.env, ...this.expandedVariables,});
336342
this.containerId = containerId.replace("\n", "");
337343

tests/cases.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ test('image <test-entrypoint>', async () => {
131131

132132
expect(mockProcessStdout).toHaveBeenCalledWith("/\n");
133133
expect(mockProcessStdout).toHaveBeenCalledWith("Hello from 'firecow/gitlab-ci-local-test-image' image entrypoint\n");
134+
expect(mockProcessStdout).toHaveBeenCalledWith("I am epic multiline value\n");
134135
expect(mockProcessStdout).toHaveBeenCalledWith("/builds\n");
135136
expect(mockProcessStdout).toHaveBeenCalledWith("Test Entrypoint\n");
136137
expect(mockProcessStdout).toHaveBeenCalledWith("I'm a test file\n");

tests/test-cases/image/.gitlab-ci.yml

+7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ test-job:
77
- echo "Test something"
88

99
test-entrypoint:
10+
# This image have an `echo ${MULTILINE_VARIABLE}` in its entry point
1011
image: firecow/gitlab-ci-local-test-image
12+
variables:
13+
MULTILINE_VARIABLE: |
14+
I am
15+
epic
16+
multiline
17+
value
1118
script:
1219
- pwd
1320
- echo "Test Entrypoint"

0 commit comments

Comments
 (0)