Building Docker images on Jenkins to use in next stage

2/12/2019

Using the kubernetes-plugin how does one build an image in a prior stage for use in a subsequent stage?

Looking at the podTemplate API it feels like I have to declare all my containers and images up front.

In semi-pseudo code, this is what I'm trying to achieve.

pod {
  container('image1') {
    stage1 {
      $ pull/build/push 'image2'
    }
  }
  container('image2') {
    stage2 {
      $ do things 
    }
  }
}
-- Joshua Barnett
docker
jenkins
kubernetes

1 Answer

2/12/2019

Jenkins Kubernetes Pipeline Plugin initializes all slave pods during Pipeline Startup. This also means that all container images which are used within the pipeline need to be available in some registry. Probably you can give us more context what you try to achieve, maybe there are other solutions for your problem.

There are for sure ways to dynamically create a pod from a build container and connect it as slave during buildtime but I feel already that this approach is not solid and will bring some complications.

-- LeonG
Source: StackOverflow