-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
76 lines (52 loc) · 1.99 KB
/
Jenkinsfile
File metadata and controls
76 lines (52 loc) · 1.99 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
72
73
74
def imageStatus = 'UNKNOWN'
pipeline {
agent any
parameters {
string(defaultValue: "repo01", description: 'this is the docker image name', name: 'dockerimagename')
string(defaultValue: "rumbledore", description: 'this is the user name of docker hub', name: 'user_docker_hub')
string(defaultValue: "rumbledore", description: 'this is the credentials id', name: 'cred_id')
password(defaultValue: "rootroot", description: 'this is the credentials id', name: 'rootDockerPass')
}
stages {
stage('Building image') {
steps {
script {
sh "cd docker"
sh "ls -ltrh "
docker.build("docker.io/${user_docker_hub}/" + "${dockerimagename}" + ":$BUILD_NUMBER", " ./docker/")
}
}
}
stage('dockerrun') {
steps {
sh " docker run -dit --name ${dockerimagename} -p 8090:80 -p 23:770 -e rootpassword=${rootDockerPass} docker.io/${user_docker_hub}/${dockerimagename}:${BUILD_NUMBER}"
}
}
stage('Testing') {
steps {
script {
imageStatus = sh(returnStdout: true, script: 'docker ps | grep "${dockerimagename}" | wc -l')
}
timeout(time: 2, unit: "HOURS") {
input message: 'Approve Deploy?', ok: 'Yes'
}
}
}
stage('clean all dockers') {
steps {
echo "${imageStatus}"
sh " docker stop ${dockerimagename} ;docker rm -f ${dockerimagename}"
}
}
stage('Push docker image') {
when {
branch 'master'
}
steps {
withDockerRegistry(credentialsId: "${cred_id}", url: '') {
sh 'docker push ${user_docker_hub}/${dockerimagename}:${BUILD_NUMBER}'
}
}
}
}
}