forked from javahometech/node-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins-docker-ansible
34 lines (33 loc) · 1.01 KB
/
jenkins-docker-ansible
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
pipeline {
agent any
environment{
DOCKER_TAG = getDockerTag()
}
stages{
stage('Build Docker Image'){
steps{
sh "docker build . -t kammana/node-app:${DOCKER_TAG} "
}
}
stage('DockerHub Push'){
steps{
withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) {
sh "docker login -u kammana -p ${dockerHubPwd}"
sh "docker push kammana/node-app:${DOCKER_TAG}"
}
}
}
stage('Deploy to Dev server'){
steps{
ansiblePlaybook extras: "-e tag=${env.DOCKER_TAG}",
credentialsId: 'slave-one',
playbook: 'ansible/docker-deploy.yml',
inventory: 'ansible/dev.inventory'
}
}
}
}
def getDockerTag(){
def tag = sh script: 'git rev-parse HEAD', returnStdout: true
return tag
}