Skip to content

Instantly share code, notes, and snippets.

@hemebond
Last active June 10, 2021 10:29
Show Gist options
  • Save hemebond/a65edc3ff49d4460a517fdd88ad588a8 to your computer and use it in GitHub Desktop.
Save hemebond/a65edc3ff49d4460a517fdd88ad588a8 to your computer and use it in GitHub Desktop.
Jenkinsfile Groovy Examples
def environments = ["development", "staging", "production"]
stage("deploy to multiple environments") {
def deployments = [:]
environments.each { e ->
deployments[e] = {
stage(e) {
podTemplate(yaml: """\
apiVersion: v1
kind: Pod
metadata:
labels:
some-label: some-label-value
spec:
containers:
- name: busybox
image: busybox
command:
- cat
tty: true
""".stripIndent())
{
node(POD_LABEL) {
container('busybox') {
echo POD_CONTAINER // displays 'busybox'
sh "hostname"
}
}
}
}
}
}
parallel deployments
}
pipeline {
agent {
label "tiny"
}
stages {
stage('Parallel Stage') {
parallel {
stage('Left') {
agent {
kubernetes {
defaultContainer 'main'
label "tiny"
}
}
steps {
script {
[
['My Test 1', 'test_1', 'test_file_1'],
['My Test 2', 'test_2', 'test_file_2'],
['My Test 3', 'test_3', 'test_file_3'],
['My Test 4', 'test_4', 'test_file_4'],
].each {
entry ->
(name, id, testFile) = entry
stage(name) {
sh label: 'Show env', script: 'env | sort'
script {
echo "${testFile}"
}
}
}
}
}
}
stage('Right') {
agent {
kubernetes {
defaultContainer 'main'
label "tiny"
}
}
stages {
stage('clone') {
steps {
script {
echo "Hello"
}
}
}
stage('r1') {
steps {
sh label: 'Show env', script: 'env | sort'
}
}
stage('r2') {
steps {
sh label: 'Show env', script: 'env | sort'
}
}
stage('r3') {
steps {
sh label: 'Show env', script: 'env | sort'
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment