-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile
147 lines (135 loc) · 5.82 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Utility method.
def sendMessage = {color, specificMessage->
// Print a message to the console and to Slack.
header = "Job <${env.JOB_URL}|${env.BRANCH_NAME}> <${env.JOB_DISPLAY_URL}|(Blue)>"
header += " build <${env.BUILD_URL}|${env.BUILD_DISPLAY_NAME}> <${env.RUN_DISPLAY_URL}|(Blue)>:"
message = "${header}\n${specificMessage}"
if (lastCommit.equals(ancestorCommit)) {
// Get last commit if we do not have a distinct ancestor.
commitHashes = [sh(script: "git log -1 --pretty=%H", returnStdout: true).trim()]
} else {
// Get max 5 commits since ancestor.
commitHashes = sh(script: "git rev-list -5 ${ancestorCommit}..", returnStdout: true).trim().tokenize('\n')
}
for (commit in commitHashes) {
author = sh(script: "git log -1 --pretty=%an ${commit}", returnStdout: true).trim()
commitMsg = sh(script: "git log -1 --pretty=%B ${commit}", returnStdout: true).trim()
message += " Commit by <@${author}> (${author}): ``` ${commitMsg} ``` "
}
echo "Message ${message}"
/* (optional snippet)
// Send a Slack message. (Note that you need to configure a Slack access token in the Jenkins system settings).
slackSend channel: 'yourchannelid', teamDomain: 'yourdomain', color: color, message: message, failOnError: true
*/
}
pipeline {
agent any
stages {
stage('Info') {
steps {
script {
/* (optional snippet)
// Generate a unique name per branch per executor; for Docker Compose to have nice image names.
// Useful for running Docker Compose commands in your scripts.
env.COMPOSE_PROJECT_NAME = "${env.BRANCH_NAME}-${env.EXECUTOR_NUMBER}"
*/
}
// Use returnStatus to not fail at this stage.
sh script: 'ci/stage_info.sh', returnStatus: true
}
}
stage('Check') {
steps {
script {
// Determine ancestor commit. This is used for two things:
// 1) Determine a list of commits for a build result message.
// 2) Check if we committed an empty branch, so we can skip the build.
//
// Note, epic is added for demonstrative purposes: epic branches are temporary develop branches,
// this can be any prefix you use for branches that can spawn feature branches.
parentBranches = '$(git branch -a --list origin/master origin/develop origin/epic/*)'
ancestorCommit = sh(
script: "git merge-base HEAD ${parentBranches}",
returnStdout: true).trim()
lastCommit = sh(script: 'git log -1 --pretty=%H', returnStdout: true).trim()
echo "==> Common ancestor is ${ancestorCommit}, last commit is ${lastCommit}."
// Check if the branch is empty, or in other words, has no new commits.
// If so, fail the build to skip it.
if (lastCommit.equals(ancestorCommit)) {
// Only skip the build when we are not an ancestor branch,
// because we always want to run those.
if (!(env.BRANCH_NAME.split('/')[0] in ['master', 'develop', 'epic'])) {
env.SKIP_BUILD = 'yes'
error('Skipping build, branch contains no new commits.')
}
}
}
}
}
stage('Build') {
steps {
sh 'ci/stage_build.sh'
}
}
stage('Test'){
steps {
sh 'ci/stage_test.sh'
junit 'build/xunit.xml'
/* (optional snippet)
// Replace the coverage source directory:
// Docker Compose uses a different path than the Jenkins workspace.
DOCKER_SOURCE_DIR=$(docker-compose run --rm --no-deps web pwd)
sed -i -r "s#<source>$DOCKER_SOURCE_DIR#<source>$WORKSPACE#" coverage.xml
*/
step([$class: 'CoberturaPublisher', coberturaReportFile: 'build/coverage.xml'])
}
}
stage('Warnings') {
steps {
// Run static analysis tools.
sh 'ci/stage_warnings.sh'
// Warnings plugin.
step([$class: 'WarningsPublisher', parserConfigurations: [
[
parserName: 'Pep8',
pattern: 'build/flake8.txt',
],
[
parserName: 'JSLint',
pattern: 'build/eslint.xml'
]
]])
// Checkstyle plugin.
checkstyle pattern: 'build/checkstyle.xml'
// The "Analysis Collector Plugin" combines the output of the Checkstyle
// plugin and the Warnings plugin into a single graph.
step([$class: 'AnalysisPublisher'])
}
}
stage('Docs') {
steps {
sh 'ci/stage_docs.sh'
publishHTML target: [reportDir: 'build/docs', reportFiles: 'index.html', reportName: 'docs']
}
}
}
post {
failure {
script {
if (!env.SKIP_BUILD) {
sendMessage '#CC0000', 'failed :scream:'
}
}
}
unstable {
script {
sendMessage '#FFA500', 'unstable :grimacing:'
}
}
success {
script {
sendMessage '#00CC00', 'successful :smiley:'
}
}
}
}