Repository navigation
Expand file tree
/
Copy pathJenkinsfile
More file actions
130 lines (94 loc) · 3.43 KB
/
Copy pathJenkinsfile
File metadata and controls
130 lines (94 loc) · 3.43 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
pipeline {
agent any
// {
// label "BuildAgent2"
// }
// environment {
// registry = "756519817970.dkr.ecr.us-east-2.amazonaws.com/postboard-server-repo"
// }
stages {
stage("Checkout") {
steps {
checkout scm
}
}
// stage("Code Coverage") {
// steps {
// jacoco()
// }
// }
stage("Build & Upload") {
steps {
sh "npm install"
}
}
// stage ("Code Quality") {
// steps {
// withSonarQubeEnv("SonarQube") {
// sh "npm install sonar-scanner"
// sh "npm run sonar"
// }
// }
// }
stage('Build and Push Docker Image') {
steps {
script {
sh 'aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin 577638372446.dkr.ecr.us-east-2.amazonaws.com'
def buildTag = "build-${env.BUILD_NUMBER}"
def latestTag = "build-${env.BUILD_NUMBER}-latest" // Dynamic 'latest' tag
// Build the image with the Jenkins build number tag
sh "docker build --no-cache -t 577638372446.dkr.ecr.us-east-2.amazonaws.com/docker-images:${buildTag} ."
// Tag the image with the dynamic 'latest' tag (not overwriting 'latest')
sh "docker tag 577638372446.dkr.ecr.us-east-2.amazonaws.com/docker-images:${buildTag} 577638372446.dkr.ecr.us-east-2.amazonaws.com/docker-images:${latestTag}"
// Push both tags to ECR
sh "docker push 577638372446.dkr.ecr.us-east-2.amazonaws.com/docker-images:${buildTag}"
sh "docker push 577638372446.dkr.ecr.us-east-2.amazonaws.com/docker-images:${latestTag}"
}
}
}
stage('Deploy Application') {
steps {
script {
// Trigger the deployment script on the target server
sshagent(['4867e2a4-980d-4950-ba51-c4ca1f763678']) {
sh '''#!/bin/bash
ssh -o StrictHostKeyChecking=no ec2-user@3.137.173.199 "
cd /home/ec2-user/main/scripts
chmod +x pull_and_deploy-nodeserver.sh
./pull_and_deploy-nodeserver.sh"
'''
}
}
}
}
// stage ("terraform init") {
// steps {
// sh ("terraform init -reconfigure")
// }
// }
// stage ("terraform plan") {
// steps {
// sh ('terraform plan')
// }
// }
// stage ("terraform apply") {
// steps {
// echo "Terraform action is --> ${action}"
// sh ('terraform ${action} --auto-approve')
// }
// }
// stage ('DEV Notify') {
// steps {
// slackSend(channel:'jenkins-server', message: "Job is successful, here is the info - Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
// }
// }
// stage ('DEV Approve') {
// steps {
// echo "Taking approval from DEV Manager for QA Deployment"
// timeout(time: 7, unit: 'DAYS') {
// input message: 'Do you approve QA Deployment?', submitter: 'admin'
// }
// }
// }
}
}