Last active
October 25, 2024 01:31
-
-
Save zacker330/5178e788e36f5861d27823908edcaef2 to your computer and use it in GitHub Desktop.
jenkins-k8s-yaml-pipeline.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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