-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeclarative_jenkinsfile_template.txt
73 lines (60 loc) · 1.54 KB
/
declarative_jenkinsfile_template.txt
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
pipeline {
//list of directives: [environment|options|parameters|triggers|stage|tools|input|when]
//Required section
//At top-level pipeline block level: must be defined here
//At stage-level: Optional usage
agent
- any
- none
- { label 'my-defined-label' }
- { node { [label | customWorkspace] '<argument>' }}
- { docker {[args | label | image] '<argument>'}}
- { dockerfile {[filename | dir | label] '<argument>'}}
//Directive
//Allowed at top-level pipeline block & each stage block
environment {
//store key:value pairs
CC = 'clang'
//credentials(): access predefined credentials by id from Jenkins environment
AN_ACCESS_KEY = credentials('my-prefined-secret-text')
}
//Only once: inside pipeline block
triggers {
-cron('H */4 * * 1-5') //example
-pollSCM('H */4 * * 1-5')
-upstream(upstreamProjects: 'job1,job2', threshold: <value>) //<comma-separated-string of jobs>
}
//Inside pipeline block or stage block
tools {
-maven 'apache-maven-3.0.1'
-jdk ''
-gradle ''
}
//Required section
//Only once: inside pipeline block
stages {
//sequence of 1 or more stage directives
stage('stage_name') {
//same as before
agent {
}
//same as before
environment {
}
//Required
//Inside each stage block
steps {
echo 'Hello World'
sh 'mvn --version'
script {
}
}
}
}
//Section
//Allowed at top-level pipeline block & each stage block
//Usually at end of pipeline
post {
[always|changed|fixed|regression|aborted|failure|success|unstable|cleanup] {}
}
}