-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
119 lines (114 loc) · 3.49 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
library(
identifier: 'jenkins-shared-library@master',
retriever: modernSCM(
[
$class: 'GitSCMSource',
remote: 'https://github.com/dhanarab/jenkins-pipeline-library.git'
]
)
)
bitbucketHttpsCredentials = "bitbucket-build-extend-https"
bitbucketCredentialsSsh = "bitbucket-build-extend-ssh"
bitbucketPayload = null
bitbucketCommitHref = null
def getCommitMessageInRange(startCommitHash, endCommitHash) {
shScript = "git log --pretty=format:'%s' " + startCommitHash + "..." + endCommitHash
return sh(returnStdout: true, script: shScript)
}
def hasBreakingChangesSymbol(commitMessages) {
if (commitMessages =~ "(feat|fix|docs|chore)(\\(.*\\))?!:") {
return true
}
return false
}
pipeline {
agent {
label "extend-builder-ci"
}
stages {
stage('Prepare') {
steps {
script {
if (env.BITBUCKET_PAYLOAD) {
bitbucketPayload = readJSON text: env.BITBUCKET_PAYLOAD
if (bitbucketPayload.pullrequest) {
bitbucketCommitHref = bitbucketPayload.pullrequest.source.commit.links.self.href
}
}
if (bitbucketCommitHref) {
bitbucket.setBuildStatus(bitbucketHttpsCredentials, bitbucketCommitHref, "INPROGRESS", env.JOB_NAME.take(30), "${env.JOB_NAME}-${env.BUILD_NUMBER}", "Jenkins", "${env.BUILD_URL}console")
}
}
}
}
stage('Lint') {
stages {
stage('Lint Commits') {
when {
expression {
return env.BITBUCKET_PULL_REQUEST_LATEST_COMMIT_FROM_TARGET_BRANCH
}
}
agent {
docker {
image 'commitlint/commitlint:19.3.1'
args '--entrypoint='
reuseNode true
}
}
steps {
sh "git config --add safe.directory '*'"
sh "commitlint --color false --verbose --from ${env.BITBUCKET_PULL_REQUEST_LATEST_COMMIT_FROM_TARGET_BRANCH}"
}
}
stage('Lint Proto') {
steps {
sh "[ -f asyncapi/buf.yaml ]" // Make sure asyncapi/buf.yaml exists
sh "[ -f proto/buf.yaml ]" // Make sure proto/buf.yaml exists
sh "make lint"
}
}
}
}
stage('Check Proto Breaking Changes') {
steps {
script {
commitMessages = getCommitMessageInRange(
env.BITBUCKET_PULL_REQUEST_LATEST_COMMIT_FROM_TARGET_BRANCH,
env.BITBUCKET_PULL_REQUEST_LATEST_COMMIT_FROM_SOURCE_BRANCH
)
echo 'Commits from pull request'
echo commitMessages
if (hasBreakingChangesSymbol(commitMessages)) {
echo 'This pull request has ! symbol, skip breaking changes checking'
} else {
sh 'make breaking -s'
}
}
}
}
stage('Check Proto Governance') {
steps {
script {
sh 'make governance'
}
}
}
}
post {
success {
script {
if (bitbucketCommitHref) {
bitbucket.setBuildStatus(bitbucketHttpsCredentials, bitbucketCommitHref, "SUCCESSFUL", env.JOB_NAME.take(30), "${env.JOB_NAME}-${env.BUILD_NUMBER}", "Jenkins", "${env.BUILD_URL}console")
}
}
}
failure {
script {
if (bitbucketCommitHref) {
bitbucket.setBuildStatus(bitbucketHttpsCredentials, bitbucketCommitHref, "FAILED", env.JOB_NAME.take(30), "${env.JOB_NAME}-${env.BUILD_NUMBER}", "Jenkins", "${env.BUILD_URL}console")
}
}
}
}
}