Skip to content

Instantly share code, notes, and snippets.

@doytsujin
Forked from zacker330/v1.groovy
Created March 9, 2022 23:44
Show Gist options
  • Save doytsujin/bdfd66133bf0f6f511617e4f005927a6 to your computer and use it in GitHub Desktop.
Save doytsujin/bdfd66133bf0f6f511617e4f005927a6 to your computer and use it in GitHub Desktop.
jenkins-k8s-yaml-pipeline.groovy
System.setProperty("org.csanchez.jenkins.plugins.kubernetes.pipeline.PodTemplateStepExecution.defaultImage", "jenkins/jnlp-slave:3.36-2")
pipeline {
agent {
kubernetes {
label 'parent-pod'
containerTemplate(name: 'jnlp', image: "jenkins/jnlp-slave:3.10-1-alpine",args: '${computer.jnlpmac} ${computer.name}')
}
}
stages {
stage('Run maven') {
agent {
kubernetes {
inheritFrom "jnlp"
containerTemplate(name: 'jnlp', image: "jenkins/jnlp-slave:3.10-1-alpine",args: '${computer.jnlpmac} ${computer.name}')
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
some-label: some-label-value
spec:
containers:
- name: maven
image: maven:alpine
command:
- cat
tty: true
- name: busybox
image: busybox
command:
- cat
tty: true
"""
}
}
steps {
echo "hello"
container('maven') {
sh 'mvn -version'
}
}
}
}
}
System.setProperty("org.csanchez.jenkins.plugins.kubernetes.pipeline.PodTemplateStepExecution.defaultImage", "jenkins/jnlp-slave:3.36-2")
pipeline {
agent {
kubernetes {
label 'parent-pod'
containerTemplate(name: 'jnlp', image: "jenkins/jnlp-slave:3.10-1-alpine",args: '${computer.jnlpmac} ${computer.name}')
}
}
stages {
stage('Run maven') {
agent {
kubernetes {
containerTemplates([
containerTemplate(name: 'maven', inheritFrom: "jnlp",image: 'maven:3.3.9-jdk-7-alpine', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'jnlp', image: "jenkins/jnlp-slave:4.3-4-alpine",args: '${computer.jnlpmac} ${computer.name}')
])
}
}
steps {
echo "hello"
container('maven') {
sh 'mvn -version'
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment