forked from ravdy/tweet-trend-new
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
104 lines (95 loc) · 3.43 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
92
93
94
95
96
97
98
99
100
101
102
103
104
def registry = 'https://titonangitechnologies.jfrog.io/'
def imageName = 'titonangitechnologies.jfrog.io/valaxy-docker-local/ttrend'
def version = '2.1.2'
pipeline {
agent {
node {
label 'maven'
}
}
environment{
PATH = "/opt/apache-maven-3.9.5/bin:$PATH"
}
stages {
stage('Build') {
steps {
echo "-------------build started---------------"
sh 'mvn clean deploy -Dmaven.test.skip=true'
echo "-------------build completed---------------"
}
}
stage('test'){
steps{
echo "-------------unit test started---------------"
sh 'mvn surefire-report:report'
echo "-------------unit test completed---------------"
}
}
stage('SonarQube analysis') {
environment{
scannerHome = tool 'tito-sonar-scanner'
}
steps{
withSonarQubeEnv('tito-sonarqube-server') { // If you have configured more than one global server connection, you can specify its name
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
stage("Quality Gate"){
steps{
script{
timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
stage("Jar Publish") {
steps {
script {
echo '<--------------- Jar Publish Started --------------->'
def server = Artifactory.newServer url:registry+"/artifactory" , credentialsId:"artifact-cred"
def properties = "buildid=${env.BUILD_ID},commitid=${GIT_COMMIT}";
def uploadSpec = """{
"files": [
{
"pattern": "jarstaging/(*)",
"target": "libs-release-local/{1}",
"flat": "false",
"props" : "${properties}",
"exclusions": [ "*.sha1", "*.md5"]
}
]
}"""
def buildInfo = server.upload(uploadSpec)
buildInfo.env.collect()
server.publishBuildInfo(buildInfo)
echo '<--------------- Jar Publish Ended --------------->'
}
}
}
stage(" Docker Build ") {
steps {
script {
echo '<--------------- Docker Build Started --------------->'
app = docker.build(imageName+":"+version)
echo '<--------------- Docker Build Ends --------------->'
}
}
}
stage (" Docker Publish "){
steps {
script {
echo '<--------------- Docker Publish Started --------------->'
docker.withRegistry(registry, 'artifact-cred'){
app.push()
}
echo '<--------------- Docker Publish Ended --------------->'
}
}
}
}
}