-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsFile
More file actions
executable file
·67 lines (66 loc) · 2.59 KB
/
Copy pathJenkinsFile
File metadata and controls
executable file
·67 lines (66 loc) · 2.59 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
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
node {
try{
def apiImage
def branchName
stage('Build') {
def scmVars = checkout scm
branchName = scmVars.GIT_BRANCH
sh "echo ${branchName}"
if(branchName == 'origin/develop') {
apiImage = docker.build("ccnoc/ccss:jarvis-${BUILD_NUMBER}", "-f Dockerfile .")
}
}
stage('Publish') {
docker.withRegistry('https://registry.hub.docker.com', 'dockerhub') {
apiImage.push();
}
}
stage('Stopping & remove Old Image'){
if(branchName == 'origin/develop') {
sshagent(['DockerDevServer']) {
sh 'ssh -o StrictHostKeyChecking=no devops@193.70.111.116 docker stop jarvis-dev || true'
sh 'ssh -o StrictHostKeyChecking=no devops@193.70.111.116 docker rm jarvis-dev || true'
}
}
}
stage('Deploy Container on Dev') {
if(branchName == 'origin/develop') {
docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){
def dockerRun = 'docker run -p 4000:3000 -d --name jarvis-dev --env-file /opt/env/jarvis-dev.conf ccnoc/ccss:jarvis-${BUILD_NUMBER}'
sshagent(['DockerDevServer']) {
sh "ssh -o StrictHostKeyChecking=no devops@193.70.111.116 ${dockerRun}"
}
}
}
}
stage("BUILD SUCCEED") {
sh "echo CICD Done"
}
stage('Removing Image') {
sh "docker rmi ccnoc/ccss:jarvis-${BUILD_NUMBER} | true"
}
stage('Docker Purge') {
sh "docker image prune -fa"
}
} catch(e) {
currentBuild.result = "FAILED"
} finally {
notifyBuild(currentBuild.result)
}
}
def notifyBuild(String buildStatus = 'SUCCESS') {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESS'
def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def summary = "${subject} (${env.BUILD_URL})"
def details = """<p>${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>"""
if(buildStatus != 'STARTED'){
emailext (
subject: subject,
body: details,
recipientProviders: [[$class: 'CulpritsRecipientProvider']],
to: 'ssqasim@csquareonline.com,ahabib@csquareonline.com,baamir@csquareonline.com,dilawar@creativechaos.co,noc-alert@csquareonline.com'
)
}
}