-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-on-prem
51 lines (43 loc) · 1.5 KB
/
Jenkinsfile-on-prem
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
pipeline {
agent {
node {
label 'master'
}
}
environment {
// Empty environment variables list
}
parameters {
string(name: 'PROJECT_VERSION', defaultValue: 'v0.0.0', description: '项目版本')
string(name: 'PROJECT_NAME', defaultValue: '', description: '项目名称')
string(name: 'TARGET_PORT', defaultValue: '', description: '服务端口')
}
stages {
stage('pull code') {
steps {
git branch: 'main',
credentialsId: 'blkmkt-jenkins-private-key',
url: 'git@github.com:ISS-owl/BLKMKT-backend.git'
}
}
stage('compile project') {
steps {
sh 'echo compile project'
sh 'mvn clean install -Dmaven.test.skip=true -gs `pwd`/mvn_settings.xml'
}
}
stage('remove old container and image') {
steps {
sh '''docker rm -f $(docker ps -a | grep $PROJECT_NAME | awk '{print $1}') || true'''
sh 'docker rmi -f $PROJECT_NAME:SNAPSHOT || true'
}
}
stage ('build and deploy') {
steps {
sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/mvn_settings.xml clean package'
sh 'cd $PROJECT_NAME && docker build -f `pwd`/Dockerfile -t $PROJECT_NAME:SNAPSHOT .'
sh 'docker run --name $PROJECT_NAME -p $TARGET_PORT:8080 -d $PROJECT_NAME:SNAPSHOT'
}
}
}
}