Interview Prep/Jenkins/Plugins, JCasC & Jenkins on Kubernetes

How does the `container()` step work?

IntermediateConceptPlugins, JCasC & Jenkins on Kubernetes
Answer

All containers in an agent pod share the workspace volume (/home/jenkins/agent). container('kaniko') { sh '...' } runs the shell step inside that container through the Kubernetes exec API, with the same working directory. So one stage can run npm test in node, then the build in kaniko, then the scan in trivy, all on the same files without stashing. The container image needs a shell (/bin/sh) for sh steps; distroless images do not have one, which is why tools ship :debug variants.

All Jenkins questions Roadmap: Jenkins

More on Plugins, JCasC & Jenkins on Kubernetes