Jenkinsfile 介绍

Jenkinsfile 是用来定义 jenkins pipeline的构建流程。

Jenkinsfile 主要有以下几个部分组成:

  1. tools: 需要使用的工具;
  2. agent: 构建的节点;
  3. stages: 构建流程,可以由多个 stage 组成;
  4. post: 构建后处理
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
pipeline {
tools {
maven "Maven 3.3.9"
jdk "Oracle JDK 8u40"
}

agent { label "any-executor" }

stages {
stage("build") {
steps {
sh 'echo "path: ${PATH}"'
sh 'echo "M2_HOME: ${M2_HOME}"'
sh 'mvn clean install -Dmaven.test.failure.ignore=true'
}
}
}

post {
always {
archive "target/**/*"
junit 'target/surefire-reports/*.xml'
}
success {
mail to:"me@example.com", subject:"SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay, we passed."
}
failure {
mail to:"me@example.com", subject:"FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed."
}
unstable {
mail to:"me@example.com", subject:"UNSTABLE: ${currentBuild.fullDisplayName}", body: "Huh, we're unstable."
}
changed {
mail to:"me@example.com", subject:"CHANGED: ${currentBuild.fullDisplayName}", body: "Wow, our status changed!"
}
}
}