forked from dareyio/php-todo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
71 lines (57 loc) · 1.74 KB
/
Copy pathJenkinsfile
File metadata and controls
71 lines (57 loc) · 1.74 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
pipeline {
agent any
environment {
DOCKERHUB_CREDENTIALS=credentials('dockerhub-cred-kebsdev')
DOCKER_REGISTRY = "hub.docker.com"
IMAGE_NAME = "kebsdev/php-todo"
IMAGE_TAG = "feature-${env.BRANCH_NAME}-0.0.${env.BUILD_NUMBER}"
}
stages {
stage("Workspace Cleanup") {
steps{
dir("$WORKSPACE") {
deleteDir()
}
}
}
stage('Checkout SCM') {
steps {
git branch: 'main', url: 'https://github.com/kebsOps/php-todo.git'
}
}
stage('Build Docker image') {
steps {
sh 'docker build -t "${IMAGE_NAME}:${IMAGE_TAG}" .'
}
}
stage("Start the app") {
steps {
script {
sh 'docker run -d -p 8000:8000 "${IMAGE_NAME}:${IMAGE_TAG}" '
}
}
}
stage("Test App") {
steps {
script{
sh 'sleep 10'
sh 'curl -I http://4.17.69.242:8000 | grep -q "HTTP/1.1 200 OK"'
}
}
}
stage('Push Docker image') {
steps {
withCredentials([string(credentialsId: 'docker-pat', variable: 'dockerpat')]) {
sh 'docker login -u kebsdev -p ${dockerpat}'
sh 'docker push "${IMAGE_NAME}:${IMAGE_TAG}"'
}
}
}
stage ('Clean Up') {
steps {
sh 'docker system prune -af'
}
}
}
}
k