-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
46 lines (40 loc) · 1.56 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
pipeline {
agent any
stages {
stage('Prepare') {
steps {
git branch: 'main',
url: 'https://github.com/CStudyTeam/CStudy-backend.git'
}
}
stage('Build Gradle') {
steps{
sh 'chmod +x gradlew'
sh './gradlew clean build'
sh 'ls -al ./build'
}
}
stage('Docker build image') {
steps{
sh 'docker build -t kimmugeon/docker-jenkins-github-cstudy .'
}
}
stage('Docker push image') {
steps{
sh 'docker login -u {id} -p {password}'
sh 'docker push kimmugeon/docker-jenkins-github-cstudy'
}
}
stage('Run Container on SSH Dev Server'){
steps{
echo 'SSH'
sshagent (credentials: ['dockerHubPwd']) {
sh "ssh -o StrictHostKeyChecking=no ubuntu@13.209.121.180 'whoami'"
sh "ssh -o StrictHostKeyChecking=no ubuntu@13.209.121.180 'docker ps -q --filter name=docker-jenkins-github-cstudy | grep -q . && docker rm -f \$(docker ps -aq --filter name=docker-jenkins-github-cstudy)'"
sh "ssh -o StrictHostKeyChecking=no ubuntu@13.209.121.180 'docker rmi -f kimmugeon/docker-jenkins-github-cstudy'"
sh "ssh -o StrictHostKeyChecking=no ubuntu@13.209.121.180 'docker run -d --name docker-jenkins-github-test -p 8081:8080 kimmugeon/docker-jenkins-github-cstudy'"
}
}
}
}
}