Skip to content

Commit a4dabb2

Browse files
committed
added pipeline
1 parent 6d945ed commit a4dabb2

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM nginx:alpine
2+
COPY . /usr/share/nginx/html
3+
EXPOSE 80

Jenkinsfile

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
pipeline {
2+
agent any
3+
4+
stages {
5+
stage('Build') {
6+
steps {
7+
script {
8+
dockerImage = docker.build("amuavia/personal-portfolio:${env.BUILD_ID}")
9+
}
10+
}
11+
}
12+
stage('Push') {
13+
steps {
14+
script {
15+
docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') {
16+
dockerImage.push()
17+
}
18+
}
19+
}
20+
}
21+
22+
stage('Test') {
23+
steps {
24+
sh 'ls -l index.html' // Simple check for index.html
25+
}
26+
}
27+
28+
stage('Deploy') {
29+
steps {
30+
script {
31+
// Deploy the new version
32+
sshPublisher(
33+
publishers: [
34+
sshPublisherDesc(
35+
configName: "MyUbuntuServer",
36+
transfers: [sshTransfer(
37+
execCommand: """
38+
docker pull amuavia/personal-portfolio:${env.BUILD_ID}
39+
docker stop personal-portfolio-container || true
40+
docker rm personal-portfolio-container || true
41+
docker run -d --name personal-portfolio-container -p 400:80 amuavia/personal-portfolio:${env.BUILD_ID}
42+
"""
43+
)]
44+
)
45+
]
46+
)
47+
48+
// Check if deployment is successful
49+
boolean isDeploymentSuccessful = sh(script: 'curl -s -o /dev/null -w "%{http_code}" http://51.20.126.236:400', returnStdout: true).trim() == '200'
50+
51+
if (!isDeploymentSuccessful) {
52+
// Rollback to the previous version
53+
def previousSuccessfulTag = readFile('previous_successful_tag.txt').trim()
54+
sshPublisher(
55+
publishers: [
56+
sshPublisherDesc(
57+
configName: "MyUbuntuServer",
58+
transfers: [sshTransfer(
59+
execCommand: """
60+
docker pull amuavia/personal-portfolio:${previousSuccessfulTag}
61+
docker stop personal-portfolio-container || true
62+
docker rm personal-portfolio-container || true
63+
docker run -d --name personal-portfolio-container -p 400:80 amuavia/personal-portfolio:${previousSuccessfulTag}
64+
"""
65+
)]
66+
)
67+
]
68+
)
69+
} else {
70+
// Update the last successful tag
71+
writeFile file: 'previous_successful_tag.txt', text: "${env.BUILD_ID}"
72+
}
73+
}
74+
}
75+
}
76+
}
77+
78+
post {
79+
failure {
80+
mail(
81+
to: 'muaviaa099@gmail.com',
82+
subject: "Failed Pipeline: ${env.JOB_NAME} [${env.BUILD_NUMBER}]",
83+
body: "Something is wrong with the build ${env.BUILD_URL}"
84+
)
85+
}
86+
}
87+
}

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div class="nav-bar">
1616
<div class="brand">
1717
<a href="#hero">
18-
<h1><span>S</span>haif <span>A</span>rfan</h1>
18+
<h1><span>A</span>meer <span>M</span>uavia</h1>
1919
</a>
2020
</div>
2121
<div class="nav-list">
@@ -42,7 +42,7 @@ <h1><span>S</span>haif <span>A</span>rfan</h1>
4242
<div>
4343
<h1>Hello, <span></span></h1>
4444
<h1>My Name is <span></span></h1>
45-
<h1>Arfan <span></span></h1>
45+
<h1>Muavia <span></span></h1>
4646
<a href="#projects" type="button" class="cta">Portfolio</a>
4747
</div>
4848
</div>

0 commit comments

Comments
 (0)