Interview Prep/CI/CD/Jenkins Pipelines and Agents

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.

All CI/CD questions

More on Jenkins Pipelines and Agents