Skip to content

Instantly share code, notes, and snippets.

@iocanel
Last active August 7, 2018 18:20
Show Gist options
  • Save iocanel/36d379bec5a96c70e7290c9c42bfa6b8 to your computer and use it in GitHub Desktop.
Save iocanel/36d379bec5a96c70e7290c9c42bfa6b8 to your computer and use it in GitHub Desktop.
A example of the kubernetes plugin with multiple build containers.
//Lets define a unique label for this build.
def label = "buildpod.${env.JOB_NAME}.${env.BUILD_NUMBER}".replace('-', '_').replace('/', '_')
//Lets create a new pod template with jnlp and maven containers, that uses that label.
podTemplate(label: label, containers: [
containerTemplate(name: 'maven', image: 'maven', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'golang', image: 'golang:1.6.3-alpine', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'jnlp', image: 'jenkinsci/jnlp-slave:alpine', command: '/usr/local/bin/start.sh', args: '${computer.jnlpmac} ${computer.name}', ttyEnabled: false)],
volumes: [
persistentVolumeClaim(mountPath: '/home/jenkins/.mvnrepo', claimName: 'jenkins-mvn-local-repo'),
secretVolume(mountPath: '/home/jenkins/.m2/', secretName: 'jenkins-maven-settings')]) {
//Lets use pod template (refernce by label)
node(label) {
git 'https://github.com/fabric8/kubernetes-model'
stage 'Genearate JSON schema'
container(name: 'golang') {
sh """
go build -a ./cmd/generate/generate.go
./generate > kubernetes-model/src/main/resources/schema/kube-schema.json
"""
}
stage 'Build model from JSON schema'
container(name: 'maven') {
sh 'mvn clean install'
}
}
}
@jmjpro
Copy link

jmjpro commented Feb 7, 2018

Is there way to declare multiple containerTemplate clauses with the DSL syntax?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment