-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
59 lines (59 loc) · 1.71 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
pipeline {
agent any
parameters {
string(name: 'tag_input', defaultValue: '', description: '部署的服务的镜像标签')
booleanParam(name: 'deploy_k8s', defaultValue: true, description: '是否在Kubernetes集群发布')
}
stages {
stage('build frontend') {
steps {
dir('src/main/webapp') {
sh '''
. /home/jenkins/.bashrc
npm i
npm run build
'''
}
}
}
stage('build backend') {
steps {
sh '''
./gradlew clean
./gradlew bootRepackage'''
}
}
stage ('def impage_path ') {
steps {
script {
def gitURLcommand = 'git config --local remote.origin.url'
tag = tag_input ?: GIT_COMMIT
gitURL = sh(returnStdout: true, script: gitURLcommand).trim()
repoName = gitURL.split('/')[-1].split('\\.')[0]
def branch2env = [master: 'test', validation: 'validation', release: 'prod']
IMAGE_PATH = "nexus-release.xsio.cn/${branch2env[env.BRANCH_NAME]}/extmms:${tag}"
echo IMAGE_PATH
IMAGE_PUB = "nexus-public.xsio.cn/${branch2env[env.BRANCH_NAME]}/extmms:${tag}"
echo IMAGE_PUB
}
}
}
stage ('docker') {
steps {
sh """
docker build -t ${IMAGE_PATH} .
docker push ${IMAGE_PATH}
docker rmi ${IMAGE_PATH} || echo
"""
}
}
stage ('deploy'){
steps {
script {
job = deploy_k8s == 'true' ? 'deploy_k8s' : 'deploy'
}
build job: "$job/$env.BRANCH_NAME", parameters: [string(name: 'IMAGE_TAG', value: tag), string(name: 'SERVICE_NAMES', value: "extmms")]
}
}
}
}