forked from Dileeprithvi/DeclarativeCI-CD-Ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
89 lines (89 loc) · 2.74 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def mvn
def server = Artifactory.server 'artifactory'
def rtMaven = Artifactory.newMavenBuild()
def buildInfo
def DockerTag() {
def tag = sh script: 'git rev-parse HEAD', returnStdout:true
return tag
}
pipeline {
agent { label 'master' }
tools {
maven 'Maven'
jdk 'JAVA_HOME'
}
options {
timestamps ()
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '10', numToKeepStr: '5')
// numToKeepStr - Max # of builds to keep
// daysToKeepStr - Days to keep builds
// artifactDaysToKeepStr - Days to keep artifacts
// artifactNumToKeepStr - Max # of builds to keep with artifacts
}
environment {
SONAR_HOME = "${tool name: 'sonar-scanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation'}"
DOCKER_TAG = DockerTag()
}
stages {
stage('Artifactory_Configuration') {
steps {
script {
rtMaven.tool = 'Maven'
rtMaven.resolver releaseRepo: 'libs-release', snapshotRepo: 'libs-snapshot', server: server
buildInfo = Artifactory.newBuildInfo()
rtMaven.deployer releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot', server: server
buildInfo.env.capture = true
}
}
}
stage('Execute_Maven') {
steps {
script {
rtMaven.run pom: 'pom.xml', goals: 'clean install', buildInfo: buildInfo
}
}
}
stage('War rename') {
steps {
sh 'mv target/*.war target/helloworld.war'
}
}
stage('SonarQube_Analysis') {
steps {
script {
scannerHome = tool 'sonar-scanner'
}
withSonarQubeEnv('sonar') {
sh """${scannerHome}/bin/sonar-scanner"""
}
}
}
stage('Quality_Gate') {
steps {
timeout(time: 3, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
stage('Build Docker Image'){
steps{
sh 'docker build -t dileep95/ansibledeploy:${DOCKER_TAG} .'
}
}
stage('Docker Container'){
steps{
withCredentials([usernamePassword(credentialsId: 'docker', passwordVariable: 'docker_pass', usernameVariable: 'docker_user')]) {
sh 'docker login -u ${docker_user} -p ${docker_pass}'
sh 'docker push dileep95/ansibledeploy:${DOCKER_TAG}'
}
}
}
stage('Ansible Playbook'){
steps {
//ansiblePlaybook credentialsId: 'ans-server', inventory: 'inventory', playbook: 'ansibleplay.yml', tags: 'stop_container,delete_container'
// Above command used to run the playbook with specified tags mentioned in the tags section.
ansiblePlaybook credentialsId: 'ans-server', inventory: 'inventory', playbook: 'ansibleplay.yml'
}
}
}
}