-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathJenkinsfile
62 lines (54 loc) · 1.89 KB
/
Jenkinsfile
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
def img
pipeline {
environment {
registry = "ashishmj/python-jenkins" //To push an image to Docker Hub, you must first name your local image using your Docker Hub username and the repository name that you created through Docker Hub on the web.
registryCredential = 'DOCKERHUB'
githubCredential = 'GITHUB'
dockerImage = ''
}
agent any
stages {
stage('checkout') {
steps {
git branch: 'master',
credentialsId: githubCredential,
url: 'https://github.com/ashish-mj/Jenkins.git'
}
}
stage ('Test'){
steps {
sh "pytest testRoutes.py"
}
}
stage ('Clean Up'){
steps{
sh returnStatus: true, script: 'docker stop $(docker ps -a | grep ${JOB_NAME} | awk \'{print $1}\')'
sh returnStatus: true, script: 'docker rmi $(docker images | grep ${registry} | awk \'{print $3}\') --force' //this will delete all images
sh returnStatus: true, script: 'docker rm ${JOB_NAME}'
}
}
stage('Build Image') {
steps {
script {
img = registry + ":${env.BUILD_ID}"
println ("${img}")
dockerImage = docker.build("${img}")
}
}
}
stage('Push To DockerHub') {
steps {
script {
docker.withRegistry( 'https://registry.hub.docker.com ', registryCredential ) {
dockerImage.push()
}
}
}
}
stage('Deploy') {
steps {
sh label: '', script: "docker run -d --name ${JOB_NAME} -p 5000:5000 ${img}"
}
}
}
}