-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
52 lines (50 loc) · 1.67 KB
/
Copy pathJenkinsfile
File metadata and controls
52 lines (50 loc) · 1.67 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
pipeline {
agent any
environment {
DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials')
}
stages {
stage('Clone repository') {
steps {
git branch: 'main', url: 'https://github.com/SH-code12/DevOps_task'
}
}
stage('Build Docker image') {
steps {
script {
// Build Docker image
sh 'docker build -t shahdelnassag/jenkins_pipeline .'
}
}
}
stage('Run Docker container') {
steps {
script {
// Stop and remove any existing container with the same name
sh 'docker stop test-jenkins-container || true'
sh 'docker rm test-jenkins-container || true'
// Run Docker container
sh 'docker run -d --name test-jenkins-container -p 5000:80 shahdelnassag/jenkins_pipeline'
}
}
}
stage('Push Docker image') {
steps {
script {
// Log in to Docker Hub using token
sh 'echo $DOCKER_HUB_CREDENTIALS_PSW | docker login -u $DOCKER_HUB_CREDENTIALS_USR --password-stdin'
// Tag the Docker image
sh 'docker tag shahdelnassag/jenkins_pipeline shahdelnassag/jenkins_pipeline:v1.0.0'
// Push the Docker image
sh 'docker push shahdelnassag/jenkins_pipeline:v1.0.0'
}
}
}
}
post {
always {
// Clean up workspace
cleanWs()
}
}
}