-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
52 lines (45 loc) · 1.63 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
pipeline {
agent any
environment{
DOCKERHUB_CREDENCIALS = credentials ('dockerhub')
RepoDockerHub = 'edgar4all'
NameContainer = 'react-todo-list'
}
stages {
stage('Lint Dockerfile') {
steps {
script {
def result = sh(script: "hadolint Dockerfile", returnStatus: true)
if (result != 0) {
error("hadolint failed with exit code ${result}")
}
}
}
}
stage('Build'){
steps{
sh "docker build -t ${env.RepoDockerHub}/${env.NameContainer}:${env.BUILD_NUMBER} ."
}
}
stage('Login to Dockerhub'){
steps{
sh "echo $DOCKERHUB_CREDENCIALS_PSW | docker login -u $DOCKERHUB_CREDENCIALS_USR --password-stdin "
}
}
stage('Push image to Dockerhub'){
steps{
sh "docker push ${env.RepoDockerHub}/${env.NameContainer}:${env.BUILD_NUMBER} "
}
}
stage('Deploy container'){
steps{
sh "if [ 'docker stop ${env.NameContainer}' ] ; then docker rm -f ${env.NameContainer} && docker run -d --name ${env.NameContainer} -p 3000:3000 ${env.RepoDockerHub}/${env.NameContainer}:${env.BUILD_NUMBER} ; else docker run -d --name ${env.NameContainer} -p 3000:3000 ${env.RepoDockerHub}/${env.NameContainer}:${env.BUILD_NUMBER} ; fi"
}
}
stage('Docker logout'){
steps{
sh "docker logout"
}
}
}
}