A build needs to run inside a pod with three containers (builder, scanner, deployer), each using a different image. How do you structure it?
IntermediateScenarioJenkins Pipelines and Agents
Answer
Situation read → Kubernetes plugin pod with multiple containers.
What I'd do →
agent {
kubernetes {
yaml '''
spec:
containers:
- name: build
image: maven:3.9-eclipse-temurin-21
command: [sleep]
args: [infinity]
- name: scan
image: aquasec/trivy:latest
command: [sleep]
args: [infinity]
'''
}
}
Then container('build') { sh 'mvn -B verify' } and container('scan') { sh 'trivy fs .' }.
Why → Containers share the workspace volume, so each tool runs in its own clean image.
Interview tip → Pin image tags or digests; latest makes builds non-reproducible.
More on Jenkins Pipelines and Agents
Your team still builds jobs by clicking through Freestyle jobs in the Jenkins UI. A new service is starting. What do you set up instead?BeginnerA Jenkins build takes 40 minutes because unit tests, linting and security scans run one after another. How do you speed it up?BeginnerBuilds queue for 20 minutes during the morning rush, but the Jenkins nodes are mostly idle at night. What do you do?IntermediateA build works on agent A but fails on agent B with "command not found: mvn". How do you stop this class of problem?BeginnerYou need a pipeline to build a branch automatically on push without polling. How do you wire it?BeginnerOnly the main branch should deploy; feature branches and PRs should only build and test. How do you express this?Beginner