Last active
June 10, 2021 10:29
-
-
Save hemebond/a65edc3ff49d4460a517fdd88ad588a8 to your computer and use it in GitHub Desktop.
Jenkinsfile Groovy Examples
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
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 | |
} |
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
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