-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsPipeline
36 lines (30 loc) · 1.16 KB
/
JenkinsPipeline
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
pipeline {
agent any
stages {
stage('Checkout') {
steps {
script {
// Clean workspace before checkout
deleteDir()
// Clone the repository and specify the branch
checkout([$class: 'GitSCM', branches: [[name: 'main']], userRemoteConfigs: [[url: 'https://github.com/akhil2099/pipeline1.git']]])
}
}
}
stage('Run Nginx Container') {
steps {
script {
// Check if the container exists
def containerExists = sh(script: 'docker ps -a --format "{{.Names}}" | grep my-nginx', returnStatus: true) == 0
// If the container exists, stop and remove it
if (containerExists) {
sh 'docker stop my-nginx'
sh 'docker rm my-nginx'
}
// Run Nginx container
sh 'docker run -d -p 80:80 --name my-nginx -v /var/lib/jenkins/workspace/project-1:/usr/share/nginx/html nginx'
}
}
}
}
}