Skip to content

Instantly share code, notes, and snippets.

@cmosgh
Created March 12, 2018 06:56
Show Gist options
  • Save cmosgh/32139a8f6188b138889e66cd05f86551 to your computer and use it in GitHub Desktop.
Save cmosgh/32139a8f6188b138889e66cd05f86551 to your computer and use it in GitHub Desktop.
Jenkins stages with different containers
podTemplate(label: 'mypod',
containers: [
containerTemplate(name: 'docker', image: 'docker', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.9.3',command:'cat', ttyEnabled: true),
containerTemplate(name: 'node', image: 'node:8.10-alpine', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'helm', image: 'lachlanevenson/k8s-helm', ttyEnabled: true, command: 'cat', priviledged: true)
],
volumes:[
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
]
){
node('mypod'){
stage('do some Docker work') {
container('docker') {
sh 'docker --version'
}
}
stage('do some node work') {
container('node') {
sh 'node --version'
}
}
stage('do some kubectl tests') {
container('kubectl') {
try {
sh 'kubectl get pods'
} catch(e) {
println e
}
}
}
stage('do some helm test') {
container('helm') {
try {
sh 'helm init -c'
sh 'helm version'
} catch(e) {
println e
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment