Skip to content

Commit cec7ccd

Browse files
authored
fix: afterscript should be reusing the same container (#1352)
1 parent 49ee889 commit cec7ccd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/job.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ export class Job {
689689

690690
this.refreshLongRunningSilentTimeout(writeStreams);
691691

692-
if (imageName) {
692+
if (imageName && !this._containerId) {
693693
await this.pullImage(writeStreams, imageName);
694694

695695
let dockerCmd = `${this.argv.containerExecutable} create --interactive ${this.generateInjectSSHAgentOptions()} `;
@@ -829,6 +829,11 @@ export class Job {
829829

830830
if (imageName) {
831831
cmd += "cd /gcl-builds \n";
832+
833+
if (expanded["CI_JOB_STATUS"] != "running") {
834+
// Ensures the env `CI_JOB_STATUS` is passed to the after_script context
835+
cmd += `export CI_JOB_STATUS=${expanded["CI_JOB_STATUS"]}\n`;
836+
}
832837
}
833838
cmd += this.generateScriptCommands(scripts);
834839

tests/test-cases/after-script/.gitlab-ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
---
22
default:
3+
image: busybox
34
after_script:
45
- echo "Cleanup after test"
56

67
test-job:
78
script:
89
- echo "Test something"
10+
- echo "cache" > /tmp/cache
911
after_script:
12+
- rm /tmp/cache
1013
- echo "Cleanup after test"
1114

1215
build-job:

0 commit comments

Comments
 (0)