-
Notifications
You must be signed in to change notification settings - Fork 752
/
Jenkinsfile
50 lines (44 loc) · 1.35 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
tools {
maven 'maven3'
}
environment {
DOCKER_TAG = getVersion()
}
stages{
stage('SCM'){
steps{
git credentialsId: 'github',
url: 'https://github.com/javahometech/dockeransiblejenkins'
}
}
stage('Maven Build'){
steps{
sh "mvn clean package"
}
}
stage('Docker Build'){
steps{
sh "docker build . -t kammana/hariapp:${DOCKER_TAG} "
}
}
stage('DockerHub Push'){
steps{
withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) {
sh "docker login -u kammana -p ${dockerHubPwd}"
}
sh "docker push kammana/hariapp:${DOCKER_TAG} "
}
}
stage('Docker Deploy'){
steps{
ansiblePlaybook credentialsId: 'dev-server', disableHostKeyChecking: true, extras: "-e DOCKER_TAG=${DOCKER_TAG}", installation: 'ansible', inventory: 'dev.inv', playbook: 'deploy-docker.yml'
}
}
}
}
def getVersion(){
def commitHash = sh label: '', returnStdout: true, script: 'git rev-parse --short HEAD'
return commitHash
}