forked from jenkinsci/kubernetes-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-kubernetes
56 lines (51 loc) · 1.89 KB
/
Jenkinsfile-kubernetes
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
/**
* Build and test the kubernetes plugin using the plugin itself in a Kubernetes cluster
*
* A `jenkins` service account needs to be created using src/main/kubernetes/service-account.yml
*
* A PersistentVolumeClaim needs to be created ahead of time with the definition in examples/maven-with-cache-pvc.yml
*
* NOTE that typically writable volumes can only be attached to one Pod at a time, so you can't execute
* two concurrent jobs with this pipeline. Or change readOnly: true after the first run
*/
def label = UUID.randomUUID().toString()
def jvmOptions = '-Xmx300M'
timestamps {
podTemplate(serviceAccount: 'jenkins', label: label, containers: [
containerTemplate(name: 'maven', image: 'maven:3.5.0-jdk-8-alpine', ttyEnabled: true, command: 'cat',
resourceRequestCpu: '100m',
resourceLimitMemory: '1200Mi')
], envVars: [
envVar(key: '_JAVA_OPTIONS', value: jvmOptions),
envVar(key: 'BRANCH_NAME', value: env.BRANCH_NAME),
envVar(key: 'BUILD_NUMBER', value: env.BUILD_NUMBER)
], volumes: [
persistentVolumeClaim(mountPath: '/root/.m2/repository-read-only', claimName: 'maven-repo', readOnly: true)
]) {
node(label) {
stage('Checkout') {
checkout scm
}
stage('Package') {
try {
container('maven') {
sh 'cp -a /root/.m2/repository-read-only /root/.m2/repository'
sh 'mvn -B clean install -Dmaven.test.skip=true -Dfindbugs.fork=false'
}
} finally {
archiveArtifacts allowEmptyArchive: true, artifacts: '**/target/*.hpi,**/target/*.jpi'
findbugs(includePattern:'**/target/findbugsXml.xml')
}
}
stage('Test') {
try {
container('maven') {
sh 'mvn -B test -DconnectorHost=0.0.0.0'
}
} finally {
junit '**/target/surefire-reports/**/*.xml'
}
}
}
}
}