forked from gouthamchilakala/PetClinic
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Jenkinsfile
91 lines (76 loc) · 2.18 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
90
91
pipeline {
agent {
label 'worker-01'
}
parameters {
string defaultValue: 'master', description: 'This is the branch to checkout the code', name: 'branch_name'
choice choices: ['DEV', 'SIT', 'UAT'], description: 'Environment to be deployed', name: 'environment'
}
triggers {
cron '00 20 * * *'
}
options {
disableConcurrentBuilds()
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '20')
timestamps()
}
tools {
jdk 'JAVA8'
maven 'MAVEN3'
}
environment {
data_path = "/opt/data/"
SCANNER_HOME = tool 'sonarqube-scanner'
}
stages {
stage('Code Checkout') {
steps {
git branch: '$branch_name', credentialsId: 'github-credentials', url: 'https://github.com/gopishank/PetClinic.git'
}
}
stage('Tests & Scans') {
parallel {
stage('Unit Testing'){
steps {
sh "mvn test"
}
}
stage('SonarQube Testing'){
steps {
withSonarQubeEnv(installationName: 'sonarqube-server') {
sh "$SCANNER_HOME/bin/sonar-scanner -Dproject.settings=sonar-project.properties"
}
}
}
}
}
stage('Package Code'){
steps {
sh "mvn package -Dmaven.test.skip=true"
}
}
stage('Upload Artifacts'){
steps {
sh '''
curl -u admin:admin123 POST "http://ec2-3-237-98-114.compute-1.amazonaws.com:8081/service/rest/v1/components?repository=petclinic" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "maven2.groupId=org.springframework.samples" -F "maven2.artifactId=petclinic" -F "maven2.version=${BUILD_ID}.0.0" -F "maven2.asset1=@${WORKSPACE}/target/petclinic.war" -F "maven2.asset1.extension=war"
'''
}
}
stage('Code Deploy'){
steps {
ansiblePlaybook installation: 'ANSIBLE29', playbook: '/opt/ansible/deploy.yaml'
}
}
}
post {
always {
echo "Always Runs the code"
}
success {
echo "Only runs when its successful"
}
failure {
echo "Only runs when the Job has failed"
}
}
}