Multi-stage builds execute CI in the last stage context instead of reverting to the job image.
Author: ivanchubbCreated Sep 25, 2024Updated Jun 2, 2025
**Actual behavior**
When executing a multi-stage build (particularly evident when the last stage is `FROM scratch`) after the `executor` finishes, the rest of the script in the CI job maintains the context of the built image instead of reverting back to the context of the image defined at the job level. This causes unexpected errors when trying to do any parsing or log aggregation after running the exeuctor.
**Expected behavior**
Expected behavior is after the executor completes, the shell would return to the context of the image specified in the CI job.
**To Reproduce**
Steps to reproduce the behavior:
1. Create a multi-stage Dockerfile where the first stage builds the binary and the second stage is `FROM scratch`
2. Create a ci job with image: `kaniko:1.23.2` where the executor is ran.
3. In the same job, after the executor runs, add to the script command that should exist in `kaniko:1.23.2`, but not in the final stage of the Dockerfile (for example: `sed`). The command will fail with "`sed` not found".
**Additional Information**
- [Dockerfile.txt](https://github.com/user-attachments/files/17134843/Dockerfile.txt)
- [build-container.txt](https://github.com/user-attachments/files/17135023/build-container.txt)
- Kaniko Image (1.23.2)
**Triage Notes for the Maintainers**
| **Description** | **Yes/No** |
|----------------|---------------|
| Please check if this a new feature you are proposing |
- - [ ]
- - [ ]
- - [ ]
- - [x]
Source: GoogleContainerTools/kaniko