-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathJenkinsfile
More file actions
42 lines (35 loc) · 1.27 KB
/
Jenkinsfile
File metadata and controls
42 lines (35 loc) · 1.27 KB
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
node(){
stage("checkout from SCM"){
git 'https://github.com/KCTechnologiesDevOps/KCMavenWebProject.git'
}
stage("Maven build"){
def mvnHome = tool name: 'M2_HOME', type: 'maven'
def mvnCMD = "${mvnHome}/bin/mvn"
sh "${mvnCMD} clean package"
}
stage("Build docker image"){
sh "docker build -t kctechnologiesdevops/batch17:${currentBuild.number} ."
}
stage("Push image"){
withCredentials([string(credentialsId: 'DOCKERHUB_CREDENTIALS', variable: 'DOCKERHUB_CREDENTIALS')]) {
sh "docker login -u kctechnologiesdevops -p ${DOCKERHUB_CREDENTIALS}"
}
sh "docker push kctechnologiesdevops/batch17:${currentBuild.number}"
}
stage("Remove existing container"){
def removeContainer = "docker rm -f MyBatch17Ctr"
try{
sshagent(['ec2-user-pem']) {
sh "ssh -o StrictHostKeyChecking=no ec2-user@13.127.66.53 ${removeContainer}"
}
}catch(error){
sh "echo No contianer exists"
}
}
stage("Create container"){
def runContainer = "docker run -itd --name MyBatch17Ctr -p 8080:8080 kctechnologiesdevops/batch17:1.0"
sshagent(['ec2-user-pem']) {
sh "ssh -o StrictHostKeyChecking=no ec2-user@13.127.66.53 ${runContainer}"
}
}
}