-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
75 lines (74 loc) · 1.8 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
pipeline {
agent {
docker {
reuseNode 'true'
registryUrl 'https://coding-public-docker.pkg.coding.net'
image 'public/docker/nodejs:12'
}
}
stages {
stage('检出') {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: '*']],
userRemoteConfigs: [[url: env.GIT_REPO_URL, credentialsId: env.CREDENTIALS_ID]]
])
script {
if ( env.MR_SOURCE_BRANCH ==~ /.*/ ) {
sh "git checkout ${env.MR_TARGET_BRANCH}"
sh "git checkout ${env.MR_SOURCE_BRANCH}"
} else {
sh "git checkout ${env.GIT_COMMIT}"
}
}
}
}
stage('安装依赖') {
steps {
sh 'npm install'
}
}
stage('检查代码规范') {
when {
changeRequest()
}
steps {
sh "git diff --diff-filter=d --name-only ${env.MR_TARGET_BRANCH}... | grep '.md\$' | xargs npx remark -f"
sh "git diff --diff-filter=d --name-only ${env.MR_TARGET_BRANCH}... | grep '.md\$' | xargs npx lint-md"
sh "npx fnlint -c .fnlint.json"
}
}
stage('增量检查 git commit') {
when {
changeRequest()
}
steps {
script {
sh 'npm install'
sh """logs=`git log --pretty=format:'%s' ${env.MR_TARGET_BRANCH}... --no-merges`;
echo "\$logs" | while read i; do echo \$i | npx commitlint; done
"""
}
}
}
stage('构建') {
steps {
sh 'npx hexo generate'
sh 'node generate-overview.js prod'
}
}
stage('部署') {
when {
anyOf {
branch 'master'
tag '*'
}
}
steps {
sh 'mv public docs && mkdir public && mv docs public'
sh 'npx hexo deploy'
}
}
}
}