-
Notifications
You must be signed in to change notification settings - Fork 28
/
Jenkinsfile
141 lines (125 loc) · 5.01 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
// A Declarative Pipeline is defined within a 'pipeline' block.
pipeline {
// agent defines where the pipeline will run.
agent {
// This also could have been 'agent any' - that has the same meaning.
label ""
// Other possible built-in agent types are 'agent none', for not running the
// top-level on any agent (which results in you needing to specify agents on
// each stage and do explicit checkouts of scm in those stages), 'docker',
// and 'dockerfile'.
}
// The tools directive allows you to automatically install tools configured in
// Jenkins - note that it doesn't work inside Docker containers currently.
tools {
// Here we have pairs of tool symbols (not all tools have symbols, so if you
// try to use one from a plugin you've got installed and get an error and the
// tool isn't listed in the possible values, open a JIRA against that tool!)
// and installations configured in your Jenkins master's tools configuration.
//jdk "jdk8"
// Uh-oh, this is going to cause a validation issue! There's no configured
// maven tool named "mvn3.3.8"!
maven "MVN_353"
}
environment {
// Environment variable identifiers need to be both valid bash variable
// identifiers and valid Groovy variable identifiers. If you use an invalid
// identifier, you'll get an error at validation time.
// Right now, you can't do more complicated Groovy expressions or nesting of
// other env vars in environment variable values, but that will be possible
// when https://issues.jenkins-ci.org/browse/JENKINS-41748 is merged and
// released.
FOO = "BAR"
}
stages {
// At least one stage is required.
stage("first stage") {
// Every stage must have a steps block containing at least one step.
steps {
// You can use steps that take another block of steps as an argument,
// like this.
//
// But wait! Another validation issue! Two, actually! I didn't use the
// right type for "time" and had a typo in "unit".
timeout(time: 10, unit: 'MINUTES') {
echo "We're not doing anything particularly special here."
echo "Just making sure that we don't take longer than five minutes"
echo "Which, I guess, is kind of silly."
// This'll output 3.3.3, since that's the Maven version we
// configured above. Well, once we fix the validation error!
sh "mvn -version"
}
}
// Post can be used both on individual stages and for the entire build.
post {
success {
echo "Only when we haven't failed running the first stage"
}
failure {
echo "Only when we fail running the first stage."
}
}
}
stage('second stage') {
// You can override tools, environment and agent on each stage if you want.
tools {
// Here, we're overriding the original maven tool with a different
// version.
maven "MVN_353"
}
steps {
echo "This time, the Maven version should be 3.5.3"
sh "mvn -version"
}
}
stage('third stage') {
steps {
// Note that parallel can only be used as the only step for a stage.
// Also, if you want to have your parallel branches run on different
// nodes, you'll need control that manually with "node('some-label') {"
// blocks inside the parallel branches, and per-stage post won't be able
// to see anything from the parallel workspaces.
// This'll be improved by https://issues.jenkins-ci.org/browse/JENKINS-41334,
// which adds Declarative-specific syntax for parallel stage execution.
parallel(one: {
echo "I'm on the first branch!"
},
two: {
echo "I'm on the second branch!"
},
three: {
echo "I'm on the third branch!"
echo "But you probably guessed that already."
})
}
}
}
post {
// Always runs. And it runs before any of the other post conditions.
always {
// Let's wipe out the workspace before we finish!
deleteDir()
}
success {
mail(from: "[email protected]",
to: "[email protected]",
subject: "That build passed.",
body: "Nothing to see here")
}
failure {
mail(from: "[email protected]",
to: "[email protected]",
subject: "That build failed!",
body: "Nothing to see here")
}
}
// The options directive is for configuration that applies to the whole job.
options {
// For example, we'd like to make sure we only keep 10 builds at a time, so
// we don't fill up our storage!
buildDiscarder(logRotator(numToKeepStr:'10'))
// And we'd really like to be sure that this build doesn't hang forever, so
// let's time it out after an hour.
timeout(time: 60, unit: 'MINUTES')
}
}