forked from Commonjava/indy-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib-build.Jenkinsfile
150 lines (147 loc) · 4.13 KB
/
lib-build.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
pipeline {
agent {
kubernetes {
cloud params.JENKINS_AGENT_CLOUD_NAME
label "jenkins-slave-${UUID.randomUUID().toString()}"
serviceAccount "jenkins"
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
app: "jenkins-${env.JOB_BASE_NAME}"
indy-pipeline-build-number: "${env.BUILD_NUMBER}"
spec:
containers:
- name: jnlp
image: quay.io/factory2/jenkins-agent:maven-36-rhel7-latest
imagePullPolicy: Always
tty: true
env:
- name: JAVA_HOME
value: /usr/lib/jvm/java-11-openjdk
- name: MAVEN_HOME
value: /opt/apache-maven-3.6.3
- name: JAVA_TOOL_OPTIONS
value: '-XX:+UnlockExperimentalVMOptions -Dsun.zip.disableMemoryMapping=true -Xms1024m -Xmx4g'
- name: MAVEN_OPTS
value: '-Xmx8g -Xms1024m -XX:MaxPermSize=512m -Xss8m'
- name: USER
value: 'jenkins-k8s-config'
- name: IMG_BUILD_HOOKS
valueFrom:
secretKeyRef:
key: img-build-hooks.json
name: img-build-hooks-secrets
- name: HOME
value: /home/jenkins
resources:
requests:
memory: 4Gi
cpu: 2000m
limits:
memory: 8Gi
cpu: 4000m
volumeMounts:
- mountPath: /home/jenkins/sonatype
name: volume-0
- mountPath: /mnt/ocp
name: volume-2
workingDir: /home/jenkins
volumes:
- name: volume-0
secret:
defaultMode: 420
secretName: sonatype-secrets
- name: volume-2
configMap:
defaultMode: 420
name: jenkins-openshift-mappings
"""
}
}
stages {
stage('git checkout') {
steps{
script{
sh """
mkdir -p /home/jenkins/.m2
mv ./settings-build.xml /home/jenkins/.m2/settings.xml
"""
checkout([$class : 'GitSCM', branches: [[name: params.LIB_GIT_BRANCH]], doGenerateSubmoduleConfigurations: false,
extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: params.LIB_NAME], [$class: 'CleanCheckout']],
submoduleCfg: [], userRemoteConfigs: [[url: params.LIB_GIT_REPO]]])
env.PR_NO = getPrNo(params.LIB_GIT_BRANCH)
env.TEMP_TAG = params.LIB_NAME + "-" + params.LIB_GIT_BRANCH + '-jenkins-' + currentBuild.id
}
}
}
stage('Build'){
steps{
dir(params.LIB_NAME){
sh "$MAVEN_HOME/bin/mvn -B -V clean verify"
}
}
}
stage('Functional test'){
steps {
dir(params.LIB_NAME){
sh "$MAVEN_HOME/bin/mvn -B -V verify -Prun-its -Pci"
}
}
}
stage('Archive') {
when{
expression {
return params.LIB_GIT_BRANCH == 'release'
}
}
steps {
echo "Archive"
archiveArtifacts artifacts: "**/*${params.LIB_NAME}*", fingerprint: true
}
}
stage('Deploy') {
steps {
dir(params.LIB_NAME){
echo "Deploy"
sh "$MAVEN_HOME/bin/mvn help:effective-settings -B -V -DskipTests=true deploy -e"
}
}
}
}
post {
success {
script {
echo "SUCCEED"
}
}
failure {
script {
if (params.MAIL_ADDRESS){
try {
sendBuildStatusEmail('failed')
} catch (e) {
echo "Error sending email: ${e}"
}
}
}
}
}
}
@NonCPS
def getPrNo(branch) {
def prMatch = branch =~ /^(?:.+\/)?pull\/(\d+)\/head$/
return prMatch ? prMatch[0][1] : ''
}
def sendBuildStatusEmail(String status) {
def recipient = params.MAIL_ADDRESS
def subject = "Jenkins job ${env.JOB_NAME} #${env.BUILD_NUMBER} ${status}."
def body = "Build URL: ${env.BUILD_URL}"
if (env.PR_NO) {
subject = "Jenkins job ${env.JOB_NAME}, PR #${env.PR_NO} ${status}."
body += "\nPull Request: ${env.PR_URL}"
}
emailext to: recipient, subject: subject, body: body
}