I was using kuberntes-plugin. In its README it has given how to write scripted pipeline with multiple container images, like
podTemplate(label: 'mypod', containers: [
containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'golang', image: 'golang:1.8.0', ttyEnabled: true, command: 'cat')
]) {
node('mypod') {
I tried the following for declarative pipeline.
pipeline {
agent {
kubernetes {
//cloud 'kubernetes'
label 'mypod'
containerTemplate {
name 'maven'
image 'maven:3.3.9-jdk-8-alpine'
ttyEnabled true
command 'cat'
}
containerTemplate {
name 'containtertwo'
image 'someimage'
ttyEnabled true
}
}
}
It creates a pod with only one container.
how to use multiple containerTemplates with declarative pipeline?
This isnt a solution to your problem, but is some information I found after looking.
The KubernetesDeclarativeAgent only has a single containerTemplate
. Whichever containerTemplate
is at the bottom of your collection of containers will be the one that is used.
In your example it will be containtertwo
.
You cant have multiple top level agents
, and you cant have multiple kubernetes
within an agent. And now you cant have multiple containers. I would prefer if an error or warning of some kind was thrown for this.
There are 2 work arounds I can think of. If you must use declarative, then you can add an agent
to your stage
, but this can lead to its own issues. The other is the scripted pipeline, which is what I am going to do.
The documentation on this leaves much to be desired.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With