-
Notifications
You must be signed in to change notification settings - Fork 48
/
Jenkinsfile
40 lines (34 loc) · 1.01 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
node{
def Namespace = "pkapp"
def ImageName = "maheshkharwadkar/mkimage"
def Creds = "mk-dockerhub-creds"
def imageTag = "1.0"
try{
stage('Checkout'){
git 'https://github.com/maheshkharwadkar/mk-k8-ci-cd.git'
//sh "git rev-parse --short HEAD > .git/commit-id"
//imageTag= readFile('.git/commit-id').trim()
}
stage('RUN Unit Tests'){
sh "npm install"
sh "npm test"
}
stage('Docker Build, Push'){
withDockerRegistry([credentialsId: "${Creds}", url: 'https://index.docker.io/v1/']) {
sh "docker build -t ${ImageName}:${imageTag} ."
sh "docker push ${ImageName}"
}
}
stage('Deploy on K8s'){
script{
sh "cd ansible/sayarapp-deploy"
sh "pwd"
sh (
script: "cd ansible/sayarapp-deploy && ansible-playbook deploy.yml --user=jenkins --extra-vars ImageName=${ImageName} --extra-vars imageTag=${imageTag} --extra-vars Namespace=${Namespace} -vv"
)
}
}
} catch (err) {
currentBuild.result = 'FAILURE'
}
}