Skip to content

Instantly share code, notes, and snippets.

@pnminh
Forked from chinshr/Jenkinsfile
Created February 4, 2018 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pnminh/7d87b583986778b0e34e583e4684b9c9 to your computer and use it in GitHub Desktop.
Save pnminh/7d87b583986778b0e34e583e4684b9c9 to your computer and use it in GitHub Desktop.
Best of Jenkinsfile, a collection of useful workflow scripts ready to be copied into your Jenkinsfile on a per use basis.
#!groovy
# Best of Jenkinsfile
# `Jenkinsfile` is a groovy script DSL for defining CI/CD workflows for Jenkins
node {
}
# Jenkinsfile
# Build and test a Maven project
node {
git url: 'https://github.com/user/repo.git'
def mvnHome = tool 'M3'
sh "${mvnHome}/bin/mvn -B -Dmaven.test.failure.ignore verify"
step([$class: 'JUnitResultArchiver', testResults:
'**/target/foobar/TEST-*.xml'])
}
# Jenkinsfile
# Verify a Maven project
node {
git url: 'https://github.com/user/repo.git'
def mvnHome = tool 'M3'
sh "${mvnHome}/bin/mvn -B verify"
}
stage "unit test"
node {
git "git@github.com:michaelneale/oaks-trail-ride.git"
sh "echo unit test app"
}
stage "test on supported OSes"
parallel (
windows: { node {
sh "echo building on windows now"
}},
mac: { node {
sh "echo building on mac now"
}}
node {
for (int i=0; i< 2; ++i) {
stage "Stage #"+i
print 'Hello, world $i!'
}
stage "Stage Parallel"
def branches = [:]
for (int i = 0; i < numHelloMessages.toInteger(); i++) {
branches["split${i}"] = {
stage "Stage parallel- #"+i
node('remote') {
echo 'Starting sleep'
sleep 10
echo 'Finished sleep'
}
}
}
parallel branches
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment