-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
50 lines (44 loc) · 1.61 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
pipeline {
agent any
environment {
COMMITHASH = getVersion()
}
stages {
stage('Build') {
steps {
dir('applications/microservice') {
sh 'docker build . -t python-microservice'
}
// sh 'cd applications/microservice; docker build . -t python-microservice'
}
}
stage ('Unit Test') {
steps {
sh 'docker run python-microservice pytest -v'
}
}
stage ('Push Build') {
steps {
sh "docker tag python-microservice 1k3tv1nay/python-microservice:${COMMITHASH}"
withCredentials([usernamePassword(credentialsId: 'dockercred', passwordVariable: 'docker_password', usernameVariable: 'docker_username')]) {
sh "docker login -u ${docker_username} -p ${docker_password}"
sh "docker push 1k3tv1nay/python-microservice:${COMMITHASH}"
}
}
}
stage ('Deploy server') {
steps {
ansiblePlaybook credentialsId: 'application-server',
disableHostKeyChecking: true,
installation: 'ansible',
inventory: 'ansible/app-inventory',
playbook: 'ansible/deploy-microservice.yml',
extras: "-e COMMITHASH=${COMMITHASH}"
}
}
}
}
def getVersion(){
def commithash = sh returnStdout: true, script: 'git rev-parse --short HEAD'
return commithash
}