-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathJenkinsfile
42 lines (39 loc) · 1.37 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
pipeline {
agent any
environment {
DOCKER_HUB_REPO = "shivammitra/flask-hello-world"
CONTAINER_NAME = "flask-hello-world"
DOCKERHUB_CREDENTIALS=credentials('dockerhub-credentials')
}
stages {
/* We do not need a stage for checkout here since it is done by default when using "Pipeline script from SCM" option. */
stage('Build') {
steps {
echo 'Building..'
sh 'docker image build -t $DOCKER_HUB_REPO:latest .'
}
}
stage('Test') {
steps {
echo 'Testing..'
sh 'docker stop $CONTAINER_NAME || true'
sh 'docker rm $CONTAINER_NAME || true'
sh 'docker run --name $CONTAINER_NAME $DOCKER_HUB_REPO /bin/bash -c "pytest test.py && flake8"'
}
}
stage('Push') {
steps {
echo 'Pushing image..'
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
sh 'docker push $DOCKER_HUB_REPO:latest'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
sh 'minikube kubectl -- apply -f deployment.yaml'
sh 'minikube kubectl -- apply -f service.yaml'
}
}
}
}