Skip to content

Commit 7c36b90

Browse files
authored
fix: services:entrypoint should support variable expansion and double quotes (#1502)
1 parent b21e517 commit 7c36b90

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/job.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,9 @@ export class Job {
13861386

13871387
if (serviceEntrypoint?.length ?? 0 > 1) {
13881388
serviceEntrypoint?.slice(1).forEach((e) => {
1389-
dockerCmd += `"${e}" `;
1389+
dockerCmd += `'${e
1390+
.replace(/'/g, "'\"'\"'") // replaces `'` with `'"'"'`
1391+
}' `;
13901392
});
13911393
}
13921394
(service.command ?? []).forEach((e) => dockerCmd += `"${e.replace(/\$/g, "\\$")}" `);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
job1:
3+
services:
4+
- name: nginx:1.27.4-alpine-slim
5+
entrypoint:
6+
- "sh"
7+
- "-c"
8+
- |
9+
cat > /usr/share/nginx/html/index.html <<EOF
10+
should support single quote [']
11+
should support double quote ["]
12+
should support variable expansion [$NGINX_VERSION]
13+
EOF
14+
/docker-entrypoint.sh nginx -g 'daemon off;'
15+
image: busybox
16+
script:
17+
- wget -qO- nginx

tests/test-cases/services/integration.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,19 @@ test.concurrent("services <no-tmp>", async () => {
140140
];
141141
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected));
142142
});
143+
144+
test("services <no-tmp>", async () => {
145+
const writeStreams = new WriteStreamsMock();
146+
await handler({
147+
cwd: "tests/test-cases/services",
148+
file: ".gitlab-ci-2.yml",
149+
noColor: true,
150+
}, writeStreams);
151+
152+
const filteredStdout = writeStreams.stdoutLines.filter(f => f.startsWith("job1 >")).join("\n");
153+
expect(filteredStdout).toEqual(`
154+
job1 > should support single quote [']
155+
job1 > should support double quote ["]
156+
job1 > should support variable expansion [1.27.4]
157+
`.trim());
158+
});

0 commit comments

Comments
 (0)