-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJenkinsfile
83 lines (75 loc) · 2.86 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
pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven "maven"
dockerTool 'Docker'
}
environment {
APPLICATION_PROPERTIES_PATH = "file:/var/jenkins_home/property/application.properties"
DOCKERHUB = credentials("dockerhub")
GITHUB_REPO='https://github.com/zosam-mosam/clink_server.git'
DOCKER_REPO="hyeyoungcho97/clink-spring"
}
stages {
stage('Git Clone'){
steps{
// Get some code from a GitHub repository
git credentialsId: 'github',
branch: 'main',
url: "$GITHUB_REPO"
}
}
stage('Build Maven') {
steps {
// Move to the directory containing pom.xml
dir('clink/') {
// Run Maven on a Unix agent.
sh "mvn -Dmaven.test.failure.ignore=true clean package -Dspring.config.location=${APPLICATION_PROPERTIES_PATH}"
}
}
}
stage ('Build Docker Image'){
steps{
script{
// Docker 이미지 빌드
sh 'docker build -t hello_spring .'
}
}
}
stage('Upload to DockerHUB') {
steps {
echo "upload"
sh 'docker login -u $DOCKERHUB_USR -p $DOCKERHUB_PSW'
sh 'docker tag hello_spring $DOCKER_REPO'
sh 'docker push $DOCKER_REPO'
sh 'docker logout'
}
}
stage('SSH transfer') {
steps([$class: 'BapSshPromotionPublisherPlugin']) {
sshPublisher(
continueOnError: false, failOnError: true,
publishers: [
sshPublisherDesc(
configName: "spring",
verbose: true,
transfers: [
sshTransfer(execCommand: "docker pull $DOCKER_REPO"),
sshTransfer(execCommand: "docker ps -aq --filter 'name=hello_world_server' | xargs -r docker stop"),
sshTransfer(execCommand: "docker ps -aq --filter 'name=hello_world_server' | xargs -r docker rm"),
sshTransfer(execCommand: "docker run -d --name hello_world_server -v /home/ubuntu/property:/var/property -p 8000:8000 $DOCKER_REPO")
// sshTransfer(sourceFiles: "helm/**",)
]
)
]
)
}
}
}
post {
always {
cleanWs() // Clean up the workspace
}
}
}