-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile
More file actions
39 lines (37 loc) · 1.07 KB
/
Jenkinsfile
File metadata and controls
39 lines (37 loc) · 1.07 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
pipeline {
environment {
// Docker registry information, please replace 'docker_hub_account' with your own.
registry = "docker_hub_account/nodejs-app-docker"
registryCredential = 'dockerhub'
// create an environment to save docker image informations
dockerImage = ''
}
agent any
stages {
// Build ing the docker image. It will run the docker build and use the jenkins build number in docker tag.
// With build number turn easeful to deploy or rollback based in jenkins.
stage('Building image') {
steps{
script {
dockerImage = docker.build registry + ":$BUILD_NUMBER"
}
}
}
// Push the docker image builded to dockerhub.
stage('Deploy Image') {
steps{
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push()
}
}
}
}
// After build and deploy, delete the image to cleanup your server space.
stage('Remove Unused docker image') {
steps{
sh "docker rmi $registry:$BUILD_NUMBER"
}
}
}
}