-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile
More file actions
120 lines (107 loc) · 5.76 KB
/
Jenkinsfile
File metadata and controls
120 lines (107 loc) · 5.76 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
112
113
114
115
116
117
118
119
120
library 'aws-access-keys@master'
pipeline {
agent { label 'ubuntu-build-slave-java17' }
parameters {
string(name: 'SDK_RELEASE_TAG', defaultValue: '', description: 'Supply version to deploy to repo1 (e.g., 4.4.8). Leave empty to deploy to reporting-new-nexus.')
}
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20'))
}
stages {
stage('CLEAN UP') {
steps {
cleanWs()
}
}
stage('SETUP BUILD') {
steps {
script {
reportiumPipeline.setupBuild()
// Override artifactTag when SDK_RELEASE_TAG is provided
if (params.SDK_RELEASE_TAG?.trim()) {
env.artifactTag = params.SDK_RELEASE_TAG
echo "Using SDK_RELEASE_TAG override: artifactTag=${artifactTag}"
}
// Echo final artifactTag for traceability (instruction #5)
echo "Build: branch=${BRANCH_NAME}, artifactTag=${artifactTag}, SDK_RELEASE_TAG=${params.SDK_RELEASE_TAG}"
}
}
}
stage('BUILD') {
steps {
script {
buildCode()
}
}
}
stage('Test') {
steps {
script {
def testSdkVersion = params.SDK_RELEASE_TAG ?: artifactTag
echo "Triggering SDK tests with version: ${testSdkVersion}"
build job: "reportium-sdk-java-test/master",
parameters: [string(name: "reportiumSdkVersion", value: "${testSdkVersion}")],
propagate: true,
wait: true
}
}
}
}
post {
always {
script {
reportiumPipeline.buildStatusNotification()
}
}
}
}
def buildCode() {
dir("$WORKSPACE/source") {
try {
withMaven(
maven: 'Maven latest',
mavenOpts: '-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/temp/dump.hprof',
mavenLocalRepo: '/home/ubuntu/.m2/repository') {
sh(script: "mvn build-helper:parse-version versions:set -DnewVersion=${artifactTag}")
sh(script: 'mvn clean install -Pcode-coverage-validation')
// Deployment logic (instruction #5: artifact flow)
boolean isReleaseBuild = (BRANCH_NAME == 'master') && (params.SDK_RELEASE_TAG?.trim())
boolean isPrBuild = (env.CHANGE_ID?.trim())
boolean isMasterBuild = (BRANCH_NAME == 'master') && !params.SDK_RELEASE_TAG?.trim()
echo "Deployment decision: branch=${BRANCH_NAME}, isRelease=${isReleaseBuild}, isPR=${isPrBuild}, isMasterBuild=${isMasterBuild}"
if (isPrBuild) {
// PR: deploy snapshot to reporting-new-nexus snapshots
def snapshotRepo = 'snapshots::default::http://reporting-new-nexus.aws-dev.perfectomobile.com/repository/maven-snapshots'
sh(script: "mvn deploy -DskipTests -Ppackage-stuff -DaltDeploymentRepository=${snapshotRepo}")
echo "PR build -> deployed SNAPSHOT ${artifactTag} to ${snapshotRepo}"
} else if (isMasterBuild) {
// Master without SDK_RELEASE_TAG: deploy release version to reporting-new-nexus maven-releases
def releaseRepo = 'releases::default::http://reporting-new-nexus.aws-dev.perfectomobile.com/repository/maven-releases'
sh(script: "mvn deploy -DskipTests -Ppackage-stuff -DaltDeploymentRepository=${releaseRepo}")
echo "Master build -> deployed release version ${artifactTag} to reporting-new-nexus: ${releaseRepo}"
} else if (isReleaseBuild) {
// Master with SDK_RELEASE_TAG: deploy to internal Nexus first (for tests), then to repo1
def releaseRepo = 'releases::default::http://reporting-new-nexus.aws-dev.perfectomobile.com/repository/maven-releases'
sh(script: "mvn deploy -DskipTests -Ppackage-stuff -DaltDeploymentRepository=${releaseRepo}")
echo "Master release build -> deployed version ${artifactTag} to internal Nexus: ${releaseRepo}"
// Also deploy to repo1 for external consumption (via pom.xml distributionManagement)
sh(script: 'mvn deploy -DskipTests -Ppackage-stuff')
echo "Master release build -> deployed version ${artifactTag} to repo1 via pom.xml distributionManagement"
// Git tag release (instruction #5: artifact flow)
sh(script: "git tag ${artifactTag} ${commitHash}")
withCredentials([usernamePassword(credentialsId: '2cb048f3-6369-4220-bbb7-2668527a8c22', passwordVariable: 'GIT_TOKEN', usernameVariable: 'GIT_USERNAME')]) {
sh "git push https://${GIT_USERNAME}:${GIT_TOKEN}@${repositoryUrl} --tags"
}
} else {
echo "No deployment: branch=${BRANCH_NAME}"
}
}
} catch (error) {
echo "Current build currentResult (buildCode - catch): ${currentBuild.currentResult}"
reportiumSlack.sendSlackMessage("${slackChannel}", "failed to compile the code, build aborted", "#e02814")
throw error
}
}
echo "Current build currentResult (buildCode): ${currentBuild.currentResult}"
}