|
1 | | -@Library('jenkins-shared-libs') |
2 | | -import edu.ksu.jenkins.* |
3 | | - |
4 | | -pipeline { |
5 | | - agent any |
6 | | - environment { |
7 | | - testDeploy = "${BRANCH_NAME}" |
8 | | - |
9 | | - regexIgnore = ".*maven-release-plugin.*;.*skipJenkins.*" |
10 | | - } |
11 | | - |
12 | | - tools { |
13 | | - maven "Maven 3.5" |
14 | | - jdk "Java 8" |
15 | | - } |
16 | | - |
17 | | - stages { |
18 | | - stage('Build') { |
19 | | - steps { |
20 | | - script { |
21 | | - if (shouldIgnoreCommit(env.regexIgnore.split(';'))) { |
22 | | - error "Ignoring commit" |
23 | | - } |
24 | | - } |
25 | | - sh 'mvn clean package -DskipTests' |
26 | | - } |
27 | | - |
28 | | - post { |
29 | | - always { |
30 | | - script { |
31 | | - if (shouldIgnoreCommit(env.regexIgnore.split(';'))) { |
32 | | - currentBuild.result = 'NOT_BUILT' |
33 | | - } |
34 | | - } |
35 | | - } |
36 | | - } |
37 | | - } |
38 | | - |
39 | | - stage('Unit Tests') { |
40 | | - steps { |
41 | | - sh 'mvn test' |
42 | | - } |
43 | | - post { |
44 | | - always { |
45 | | - junit '**/target/surefire-reports/*.xml' |
46 | | - } |
47 | | - failure { |
48 | | - itsChat Constants.DEFAULT_CHANNEL, "${env.JOB_NAME} had unit test failures on branch ${env.BRANCH_NAME} \nRecent Changes - ${getChangeString(10)}\nBuild: ${BUILD_URL}" |
49 | | - } |
50 | | - unstable { |
51 | | - itsChat Constants.DEFAULT_CHANNEL, "${env.JOB_NAME} had unit test failures on branch ${env.BRANCH_NAME} \nRecent Changes - ${getChangeString(10)}\nBuild: ${BUILD_URL}" |
52 | | - } |
53 | | - changed { |
54 | | - script { |
55 | | - if (currentBuild.result == null || currentBuild.result == 'SUCCESS') { |
56 | | - itsChat Constants.DEFAULT_CHANNEL, "${env.JOB_NAME} now has passing unit tests on branch ${env.BRANCH_NAME} \nRecent Changes - ${getChangeString(10)}\nBuild: ${BUILD_URL}" |
57 | | - } |
58 | | - } |
59 | | - } |
60 | | - } |
61 | | - } |
62 | | - |
63 | | - stage('Sonar') { |
64 | | - when { |
65 | | - branch 'master' |
66 | | - } |
67 | | - steps { |
68 | | - sh 'mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install' |
69 | | - sh "mvn sonar:sonar -P sonar -Dsonar.branch=${env.branch_name}" |
70 | | - } |
71 | | - } |
72 | | - |
73 | | - stage('Maven Site') { |
74 | | - when { branch 'master' } |
75 | | - steps { |
76 | | - sh 'mvn site-deploy' |
77 | | - } |
78 | | - post { |
79 | | - success { |
80 | | - itsChat 'javabuilds', "Successfully generated Maven site documentation for canvas-api: https://jenkins.ome.ksu.edu/maven-site/canvas-api/" |
81 | | - } |
82 | | - } |
83 | | - } |
84 | | - |
85 | | - |
86 | | - } |
87 | | - post { |
88 | | - always { |
89 | | - deleteDir() |
90 | | - } |
91 | | - } |
92 | | -} |
93 | | - |
94 | | -@NonCPS |
95 | | -def version() { |
96 | | - pom = readMavenPom file: 'pom.xml' |
97 | | - pom.version |
98 | | -} |
99 | | - |
100 | | -def shouldIgnoreCommit(regexIgnoreList) { |
101 | | - def lastCommit = sh (script: 'git log --pretty=oneline | head -n 1', returnStdout: true) |
102 | | - // For loop is used because [].each is not serializable |
103 | | - for (int i = 0; i < regexIgnoreList.size(); i++) { |
104 | | - if (lastCommit =~ /${regexIgnoreList[i]}/) { |
105 | | - return true |
106 | | - } |
107 | | - } |
108 | | - return false |
109 | | -} |
110 | | - |
111 | | -@NonCPS |
112 | | -def getChangeString(maxMessages) { |
113 | | - MAX_MSG_LEN = 100 |
114 | | - COMMIT_HASH_DISPLAY_LEN = 7 |
115 | | - def changeString = "" |
116 | | - |
117 | | - def changeLogSets = currentBuild.changeSets |
118 | | - |
119 | | - |
120 | | - for (int i = 0; i < changeLogSets.size(); i++) { |
121 | | - def entries = changeLogSets[i].items |
122 | | - for (int j = 0; j < entries.length && i + j < maxMessages; j++) { |
123 | | - def entry = entries[j] |
124 | | - truncated_msg = entry.msg.take(MAX_MSG_LEN) |
125 | | - commitHash = entry.commitId.take(COMMIT_HASH_DISPLAY_LEN) |
126 | | - changeString += "${commitHash}... - ${truncated_msg} [${entry.author}]\n" |
127 | | - } |
128 | | - } |
129 | | - |
130 | | - if (!changeString) { |
131 | | - changeString = " There have not been changes since the last build" |
132 | | - } |
133 | | - return changeString |
134 | | -} |
| 1 | +@Library('jenkins-shared-libs') _ |
| 2 | +def config = [ appName: 'canvas-api', |
| 3 | + podName: 'java-11-maven-3.5.2.yaml', |
| 4 | + containerName: 'jdk-11-maven', |
| 5 | + runUnitTests: true, |
| 6 | + runIntegrationTests: false |
| 7 | + ] |
| 8 | +javaPipeline(config) |
0 commit comments