forked from barathtech/node-hello
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
75 lines (69 loc) · 2.65 KB
/
Jenkinsfile
File metadata and controls
75 lines (69 loc) · 2.65 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
68
69
70
71
72
73
74
75
pipeline {
agent { label 'slave1' }
environment {
AWS_ACCOUNT_ID="246069437619"
AWS_DEFAULT_REGION="us-east-1"
REPOSITORY_URI = "246069437619.dkr.ecr.us-east-1.amazonaws.com/adminnew"
IMAGE_TAG="246069437619.dkr.ecr.us-east-1.amazonaws.com/adminnew" + ":" +"${BUILD_NUMBER}"
JOB_NAME= "${env.JOB_NAME}"
RELEASE_NOTES= sh(script: "git show -s --pretty=format:%h", returnStdout: true).trim()
COMMIT_MESSAGE= sh(script: "git show -s --pretty=%s", returnStdout: true).trim()
Author_Name= sh(script: "git show -s --pretty=%an", returnStdout: true).trim()
IMAGE= "246069437619.dkr.ecr.us-east-1.amazonaws.com/adminnew"
LAST_BUILD= "${currentBuild.previousBuild.number}"
HEALTH= "${env.IMAGE}"+ ":" +"${env.LAST_BUILD}"
}
stages {
stage('Logging into AWS ECR') {
steps {
script {
sh "aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 246069437619.dkr.ecr.us-east-1.amazonaws.com"
}
}
}
stage('Cloning Git') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '', url: 'https://github.com/ArasanKavi/node-hello.git']]])
}
}
// Building Docker images
stage('Building image') {
steps{
script {
sh "docker build -t ${env.IMAGE_TAG} ."
}
}
}
// Uploading Docker images into AWS ECR
stage('Pushing to ECR') {
steps{
script {
sh """
docker push ${env.IMAGE_TAG}
sed -i "s|newimage|${env.IMAGE_TAG}|g" docker-compose.yml
docker-compose up -d
"""
}
}
}
stage('Run Container on Server Dev') {
steps{
sh """
docker rmi -f ${env.HEALTH}
"""
}
}
stage("Triggering") {
steps {
script{
withCredentials([string(credentialsId: 'continous-integration-token', variable: 'TOKEN'),
string(credentialsId: 'telegramidgroup', variable: 'CHAT_ID')]) {
sh """
curl -X POST https://api.telegram.org/bot${TOKEN}/sendMessage -d chat_id=${CHAT_ID} -d text="Hi, Jenkins job: ${JOB_NAME} status is ${currentBuild.currentResult} , Committed by : ${env.Author_Name} , commit-id : ${env.RELEASE_NOTES} , commit msg : ${env.COMMIT_MESSAGE}"
"""
}
}
}
}
}
}