-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
83 lines (83 loc) · 2.63 KB
/
Jenkinsfile
File metadata and controls
83 lines (83 loc) · 2.63 KB
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
pipeline {
agent any // 构建代理, any 表示任意,常见的有 docker{}
options {
timeout(time: 30, unit: 'MINUTES') // 构建超时
// buildDiscarder(logRotator(numToKeepStr:'10')) // 保留构建数量 10 个
}
stages { // 阶段列表
stage('Print Environment') { // 阶段 环境变量打印
steps { // 执行步奏
echo '=> print Environment start'
echo "NODE_NAME= ${NODE_NAME}"
echo "JENKINS_HOME= ${JENKINS_HOME}"
echo "JENKINS_URL= ${JENKINS_URL}"
echo "WORKSPACE= ${WORKSPACE}"
echo "JOB_NAME= ${JOB_NAME}"
echo "BUILD_URL= ${BUILD_URL}"
echo "BUILD_ID= ${BUILD_ID}"
echo "BUILD_NUMBER= ${BUILD_NUMBER}"
echo "BUILD_TAG= ${BUILD_TAG}"
echo '=> print Environment end'
}
}
stage('Debug jenkins') { // 调试 jk
steps {
print '=> Debug begin'
echo "-> Prints public args"
echo '${PATH}'
echo "${PATH}"
echo "-> Prints jenkins args"
echo 'DEPLOY_TO= ${DEPLOY_TO} Parameter build needs to be set, otherwise an error is reported No such property:'
echo "-> Prints the currently set environment variable"
echo 'GOPROXY= ${GOPROXY}'
echo "GOPROXY= ${GOPROXY}"
print '=> Debug End'
echo 'Multi-line shell execution'
sh '''
whoami
pwd
ls
'''
}
}
stage('Print environment android') { // 调试 jk
steps {
print '=> print android env'
echo "JAVA_HOME= ${JAVA_HOME}"
echo "java -version"
java -version
echo "GRADLE_HOME= ${GRADLE_HOME}"
echo "gradle -version"
gradle -version
echo "ANDROID_HOME= ${ANDROID_HOME}"
echo "adb version"
adb version
}
}
// stage('Checkout SCM') {
// steps {
// checkout scm
// sh 'git --no-pager rev-parse HEAD --short HEAD'
// sh 'git --no-pager log --oneline -1 --pretty=format:"%h - %an, %ar : %s"'
// }
// }
stage('Example Deploy') {
when {
expression { // 条件为构建成功
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
branch 'production' // 分支为 production
environment name: 'DEPLOY_TO', value: 'production' // DEPLOY_TO 值为 production
}
steps {
echo "Deploying DEPLOY_TO= ${DEPLOY_TO}"
archiveArtifacts artifacts: '**/build/*.apk', allowEmptyArchive: true
}
}
stage('Info more') {
steps {
echo "more see https://www.jenkins.io/zh/doc/book/pipeline/jenkinsfile/"
}
}
}
}