-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
74 lines (64 loc) · 2.28 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!groovy
import groovy.json.JsonOutput
node {
// pull request or feature branch
if (env.GITHUB_REF != 'refs/heads/master') {
checkoutSource()
build()
unitTest()
} // master branch / production
else {
checkoutSource()
build()
allTests()
createRelease("${env.GITHUB_ACTION}-${env.GITHUB_SHA}")
}
}
def createRelease(name) {
stage ('createRelease') {
def payload = JsonOutput.toJson(["tag_name": "v-${name}", "name": "GitHub Action triggered release: ${name}", "body": "This release has been created with the help of a Jenkins single-shot master running inside of a GitHub Action. For more details visit https://github.com/jonico/jenkinsfile-runner-github-actions"])
def apiUrl = "https://api.github.com/repos/${env.GITHUB_REPOSITORY}/releases"
mysh("curl -s --output /dev/null -H \"Authorization: Token ${env.GITHUB_TOKEN}\" -H \"Accept: application/json\" -H \"Content-type: application/json\" -X POST -d '${payload}' ${apiUrl}")
}
}
// prevent output of secrets and a globbing patterns by Jenkins
def mysh(cmd) {
sh('#!/bin/sh -e\n' + cmd)
}
def checkoutSource() {
stage ('checkoutSource') {
// as the commit that triggered that Jenkins action is already mapped to /github/workspace, we just copy that to the workspace
copyFilesToWorkSpace()
}
}
def copyFilesToWorkSpace() {
mysh "cp -r /github/workspace/* $WORKSPACE"
}
def build () {
stage ('Build') {
mvn 'clean install -DskipTests=true -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -B -V'
}
}
def unitTest() {
stage ('Unit tests') {
mvn 'test -B -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true'
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
if (currentBuild.result == "UNSTABLE") {
sh "exit 1"
}
}
}
def allTests() {
stage ('All tests') {
// don't skip anything
mvn 'test -B'
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
if (currentBuild.result == "UNSTABLE") {
// input "Unit tests are failing, proceed?"
sh "exit 1"
}
}
}
def mvn(args) {
sh "mvn ${args} -Dmaven.test.failure.ignore -Dmaven.repo.local=/github/workspace/.m2"
}