forked from abdelrahmanonline4/sourcecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
64 lines (56 loc) · 1.6 KB
/
Copy pathJenkinsfile
File metadata and controls
64 lines (56 loc) · 1.6 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
pipeline {
agent any
environment {
IMAGE_NAME = 'nodejs-docker-app'
CONTAINER_NAME = 'nodejs-docker-container'
APP_PORT = '3000'
}
stages {
stage('Checkout') {
steps {
echo 'Checking out source code from GitHub...'
checkout scm
}
}
stage('Build Docker Image') {
steps {
echo 'Building Docker image...'
sh '''
docker build -t $IMAGE_NAME:$BUILD_NUMBER -t $IMAGE_NAME:latest .
'''
}
}
stage('Run Container') {
steps {
echo 'Removing old container if it exists...'
sh '''
docker rm -f $CONTAINER_NAME || true
'''
echo 'Running new container...'
sh '''
docker run -d \
--name $CONTAINER_NAME \
-p $APP_PORT:3000 \
$IMAGE_NAME:$BUILD_NUMBER
'''
}
}
stage('Verify') {
steps {
echo 'Verifying running container...'
sh '''
docker ps --filter "name=$CONTAINER_NAME"
curl -I http://localhost:$APP_PORT || true
'''
}
}
}
post {
success {
echo 'Pipeline completed successfully. Node.js Docker app is running on port 3000.'
}
failure {
echo 'Pipeline failed. Check Jenkins console output.'
}
}
}