forked from jenkinsci/configuration-as-code-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlauda.Jenkinsfile
180 lines (163 loc) · 4.3 KB
/
Alauda.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// https://jenkins.io/doc/book/pipeline/syntax/
@Library('alauda-cicd') _
// global variables for pipeline
def GIT_BRANCH
def GIT_COMMIT
def FOLDER = "."
// image can be used for promoting...
def IMAGE
def CURRENT_VERSION
def code_data
def DEBUG = false
def RELEASE_VERSION
def TEST_IMAGE
def hpiRelease
pipeline {
// 运行node条件
// 为了扩容jenkins的功能一般情况会分开一些功能到不同的node上面
// 这样每个node作用比较清晰,并可以并行处理更多的任务量
agent { label 'java' }
// (optional) 流水线全局设置
options {
// 保留多少流水线记录(建议不放在jenkinsfile里面)
buildDiscarder(logRotator(numToKeepStr: '10'))
// 不允许并行执行
disableConcurrentBuilds()
}
parameters {
booleanParam(name: 'DEBUG', defaultValue: false, description: 'DEBUG the pipeline')
}
//(optional) 环境变量
environment {
// for building an scanning
JENKINS_IMAGE = "jenkins/jenkins:lts"
REPOSITORY = "configuration-as-code-plugin"
PLUGIN_NAME = "configuration-as-code"
OWNER = "alauda"
IMAGE_TAG = "dev"
// sonar feedback user
// needs to change together with the credentialsID
SCM_FEEDBACK_ACCOUNT = "alaudabot"
SONARQUBE_SCM_CREDENTIALS = "alaudabot"
DINGDING_BOT = "devops-chat-bot"
TAG_CREDENTIALS = "alaudabot-github"
}
// stages
stages {
stage('Checkout') {
steps {
script {
DEBUG = params.DEBUG
// checkout code
echo 'start to checkout code'
def scmVars = checkout scm
echo 'done with code clone'
// extract git information
env.GIT_COMMIT = scmVars.GIT_COMMIT
env.GIT_BRANCH = scmVars.GIT_BRANCH
GIT_COMMIT = "${scmVars.GIT_COMMIT}"
GIT_BRANCH = "${scmVars.GIT_BRANCH}"
hpiRelease = deploy.HPIRelease(scmVars)
hpiRelease.debug = DEBUG
hpiRelease.calculate()
RELEASE_VERSION = hpiRelease.releaseVersion
echo "RELEASE_VERSION ${RELEASE_VERSION}"
}
}
}
stage('CI'){
steps {
script {
container('java'){
sh """
mvn clean install -U -Dmaven.test.skip=true
"""
}
archiveArtifacts 'plugin/target/*.hpi'
}
}
}
stage("Code Scan"){
failFast true
parallel {
stage("Code Scan"){
steps{
container("tools"){
script{
if(env.BRANCH_NAME == "alauda"){
env.BRANCH_NAME = "master"
deploy.scan().startACPSonar(null, "-D sonar.projectVersion=${RELEASE_VERSION}")
} else {
env.BRANCH_NAME = "alauda"
}
}
}
}
}
stage('Sec Scan'){
steps {
script{
def sec = deploy.secScan("java", false, 1)
sec.containerName = 'java'
container(sec.containerName){
sec.install().start()
}
}
}
}
}
}
stage('Deploy to Nexus') {
steps{
script{
hpiRelease.deploy("-Dmaven.test.skip=true -Dmaven.site.skip=true -Dmaven.javadoc.skip=true")
if(hpiRelease.deployToUC){
hpiRelease.triggerBackendIndexing(RELEASE_VERSION)
hpiRelease.waitUC(PLUGIN_NAME, RELEASE_VERSION, 15)
}
}
}
}
// after build it should start deploying
stage('Tag Git') {
// limit this stage to master or release only
when {
expression { hpiRelease.shouldTag }
}
steps {
script {
// adding tag to the current commit
withCredentials([usernamePassword(credentialsId: deploy.getAlaudaCredentialID(TAG_CREDENTIALS), passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh "git tag -l | xargs git tag -d" // clean local tags
sh """
git config --global user.email "[email protected]"
git config --global user.name "Alauda Bot"
"""
def repo = "https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${OWNER}/${REPOSITORY}.git"
sh "git fetch --tags ${repo}" // retrieve all tags
sh("git tag -a ${hpiRelease.tag} -m 'auto add release tag by jenkins'")
sh("git push ${repo} --tags")
}
}
}
}
stage("Delivery Jenkins") {
when {
expression { hpiRelease.deliveryJenkins }
}
steps {
script {
hpiRelease.triggerJenkins(PLUGIN_NAME, "io.jenkins;${RELEASE_VERSION}")
}
}
}
}
post {
always {
junit allowEmptyResults: true, testResults: "**/target/surefire-reports/**/*.xml"
script {
deploy.alaudaNotification([:])
}
}
}
}