-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
111 lines (96 loc) · 3.35 KB
/
Jenkinsfile
File metadata and controls
111 lines (96 loc) · 3.35 KB
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
105
106
107
108
109
110
111
#!/usr/bin/env groovy
@Library(['piper-lib', 'cas-central-jenkins-library']) _
def repoOrg = 'CPSecurity'
def repoName = 'ams-samples-java'
def repoFullName = repoOrg + '/' + repoName
def isBranchIndexingCause() {
return currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')
}
if (isBranchIndexingCause()) {
// Aborts the build if triggered via Branch Indexing
print "INFO: Build skipped due to trigger being Branch Indexing"
currentBuild.result = 'ABORTED'
return
}
properties([
buildDiscarder(
logRotator(artifactDaysToKeepStr: '-1', artifactNumToKeepStr: '-1', daysToKeepStr: '-1', numToKeepStr: '10')
)
])
try {
node('ams-agent') {
if (job.isTriggeredByDepB()) {
stage('Setup') {
prepareScm()
}
def projectVersion = getMavenVersion()
updateVersionAndPushChangesArtifactory treeish: treeish, artifactVersion: projectVersion, repoFullName: repoFullName
} else {
stage('Setup') {
prepareScm()
}
stage('Unit Tests') {
lock(resource: 'UNIT_TESTS', inversePrecedence: true) {
unitTests()
}
}
stage('Integration Test') {
integrationTests()
}
}
}
} catch (Throwable err) { // catch all exceptions
globalPipelineEnvironment.addError(this, err)
throw err
} finally{
node('ams-agent'){
// At this point as the build is successful, we can clean the workspace
cleanWorkspace()
}
}
def getMavenVersion() {
def mavenPom = readMavenPom (file: 'jakarta-ams-sample/pom.xml')
def mavenVersion = mavenPom.getVersion().split("-", 2)[0]
echo "Maven Version: ${mavenVersion}"
return mavenVersion
}
// ===============================================
// Misc Utils
// ===============================================
def prepareScm() {
deleteDir()
checkout scm
}
def unitTests() {
parallel(
'Spring': {
dir('spring-security-ams') {
sh 'mvn -q clean test -U --settings ../.pipeline/maven-settings.xml -Dmaven.repo.local=${HOME}/.m2/spring-security-ams/repository'
// get results for the jenkins junit plugin
junit 'target/surefire-reports/*.xml'
}
},
'Jakarta': {
dir('jakarta-ams-sample') {
sh 'mvn dependency:purge-local-repository -q clean test -U --settings ../.pipeline/maven-settings.xml -Dmaven.repo.local=${HOME}/.m2/jakarta-ams-sample/repository'
// get results for the jenkins junit plugin
junit 'target/surefire-reports/*.xml'
}
}
)
}
def integrationTests() {
if (env.BRANCH_NAME.startsWith('PR-')) {
environment = 'dev'
if (env.CHANGE_TARGET == 'master') {
environment = 'cc3-qa-rot'
}
build job: 'CPSecurity/cas-ams-e2e-tests/master', parameters: [
booleanParam(name: 'DEPLOY', value: true),
booleanParam(name: 'TEST', value: true),
booleanParam(name: 'NOTIFY', value: false),
string(name: 'ENVIRONMENT', value: environment),
string(name: 'TREEISH_SAMPLES', value: env.CHANGE_BRANCH)
]
}
}