This repository has been archived by the owner on Jul 17, 2022. It is now read-only.
forked from oekstein/DevOpsInterviewAssignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
55 lines (55 loc) · 1.69 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
pipeline {
agent {
label "jenkins-slave"
}
environment {
DOCKER_CRED = credentials('dockerhub')
}
options {
buildDiscarder(logRotator(numToKeepStr: '20', daysToKeepStr: '5' ))
}
stages {
stage('Pull Code') {
steps {
script {
checkout scm
}
}
}
stage('run unittests') {
steps {
script {
sh "sudo apt-get install libmagic1 -y"
env.VIRTUAL_ENV="./venv"
sh "python3 -m virtualenv venv"
env.PATH="$VIRTUAL_ENV/bin:$PATH"
sh "pip3 install -r requirements.txt"
sh "python3 -m unittest microservice/tests/test_service.py"
}
}
}
stage('build and push image') {
steps {
script {
sh """
docker build -t erzez/bitdam1:${BUILD_NUMBER} .
docker login --username $DOCKER_CRED_USR --password $DOCKER_CRED_PSW
docker push erzez/bitdam1:${BUILD_NUMBER}
"""
}
}
}
stage('deploy image') {
steps {
script {
withCredentials([file(credentialsId: 'kubeconfig', variable: 'config')]) {
sh """
export KUBECONFIG=\${config}
kubectl set image deployment/microservice-deployment microservice=erzez/bitdam1:${BUILD_NUMBER}
"""
}
}
}
}
}
}