-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinfile.gradle.ci
81 lines (78 loc) · 2.54 KB
/
Jenkinfile.gradle.ci
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
#!/usr/bin/env groovy
//
// Gradle Pipeline
//
// Repository | https://github.com/DevOpsSampleOrg/jenkins-pipeline/tree/master/Jenkinfile.gradle.ci
// Environment | AWS
// AWS Key | Not required
// JDK | openjdk8
// Build Tool | gradle-6-9, Update the Gradle wrapper file permission with 'git update-index --chmod=+x gradlew'
// Parameters |----------------------------------------------------------------------|
// | 1 | REPO_URL | Mandatory | GitHub/CodeCommit URL |
// | 2 | BRANCH | Mandatory | develop, feature_xxx, master |
// | 3 | PR_ID | Optional | Pull Request ID |
// | 4 | STAGE | Mandatory | dev, stg, prd |
//
def repoUrl = params.REPO_URL
pipeline {
// agent {
// node {
// label slaveNode
// }
// }
agent any
tools {
gradle 'gradle-6-9'
}
options {
timestamps()
buildDiscarder(logRotator(numToKeepStr:'20'))
}
stages {
stage('Cleanup Workspace') {
steps {
cleanWs()
}
}
stage('Checkout') {
steps {
script {
git url: repoUrl, branch: params.BRANCH, credentialsId: env.GIT_CREDENTIALS_ID
}
}
}
stage('Build') {
steps {
sh 'gradle build -x test'
}
}
stage('Test') {
steps {
sh 'gradle test -Penv='+ params.STAGE
}
post {
always {
junit 'build/test-results/test/*.xml'
jacoco()
}
}
}
stage("SonarQube Quality Gate") {
steps {
withSonarQubeEnv('sonarserver') {
script {
def sonarCmd = 'gradle sonar -x test'
if (params.PR_ID != '') {
sonarCmd += ' -Dsonar.pullrequest.key='+ params.PR_ID
sonarCmd += ' -Dsonar.pullrequest.branch='+ params.BRANCH
sonarCmd += ' -Dsonar.pullrequest.base='+ params.BASE_BRANCH
sonarCmd += ' -Dsonar.pullrequest.github.repository='+ repoUrl
}
sh sonarCmd
}
}
waitForQualityGate abortPipeline: true
}
}
}
}