-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
83 lines (83 loc) · 4.21 KB
/
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
#!groovy
pipeline {
environment {
PROJECT_NAME = "keypop-reader-java-api"
PROJECT_BOT_NAME = "Eclipse Keypop Bot"
}
agent { kubernetes { yaml javaBuilder('1.0') } }
stages {
stage('Import keyring') {
when { expression { env.GIT_URL.startsWith('https://github.com/eclipse-keypop/keypop-') && env.CHANGE_ID == null } }
steps { container('java-builder') {
withCredentials([file(credentialsId: 'secret-subkeys.asc', variable: 'KEYRING')]) { sh 'import_gpg "${KEYRING}"' }
} }
}
stage('Prepare settings') { steps { container('java-builder') {
script {
env.KEYPOP_VERSION = sh(script: 'grep version gradle.properties | cut -d= -f2 | tr -d "[:space:]"', returnStdout: true).trim()
env.GIT_COMMIT_MESSAGE = sh(script: 'git log --format=%B -1 | head -1 | tr -d "\n"', returnStdout: true)
echo "Building version ${env.KEYPOP_VERSION} in branch ${env.GIT_BRANCH}"
deployRelease = env.GIT_URL == "https://github.com/eclipse-keypop/${env.PROJECT_NAME}.git" && (env.GIT_BRANCH == "main" || env.GIT_BRANCH == "release-${env.KEYPOP_VERSION}") && env.CHANGE_ID == null && env.GIT_COMMIT_MESSAGE.startsWith("Release ${env.KEYPOP_VERSION}")
deploySnapshot = !deployRelease && env.GIT_URL == "https://github.com/eclipse-keypop/${env.PROJECT_NAME}.git" && (env.GIT_BRANCH == "main" || env.GIT_BRANCH == "release-${env.KEYPOP_VERSION}") && env.CHANGE_ID == null
}
sh "chmod +x ./gradlew ./scripts/*.sh"
} } }
stage('Check version') {
steps { container('java-builder') {
sh "./scripts/check_version.sh ${env.KEYPOP_VERSION}"
} }
}
stage('Build and Test') {
when { expression { !deploySnapshot && !deployRelease } }
steps { container('java-builder') {
sh './gradlew clean build test --no-build-cache --info --stacktrace'
junit testResults: 'build/test-results/test/*.xml', allowEmptyResults: true
} }
}
stage('Build and Publish Snapshot') {
when { expression { deploySnapshot } }
steps { container('java-builder') {
configFileProvider([configFile(fileId: 'gradle.properties', targetLocation: '/home/jenkins/agent/gradle.properties')]) {
sh './gradlew clean build test publish --info --stacktrace'
}
junit testResults: 'build/test-results/test/*.xml', allowEmptyResults: true
} }
}
stage('Build and Publish Release') {
when { expression { deployRelease } }
steps { container('java-builder') {
configFileProvider([configFile(fileId: 'gradle.properties', targetLocation: '/home/jenkins/agent/gradle.properties')]) {
sh './gradlew clean build test release --info --stacktrace'
}
junit testResults: 'build/test-results/test/*.xml', allowEmptyResults: true
} }
}
stage('Update GitHub Pages') {
when { expression { deploySnapshot || deployRelease } }
steps { container('java-builder') {
sh "./scripts/prepare_javadoc.sh ${env.PROJECT_NAME} ${env.KEYPOP_VERSION} ${deploySnapshot}"
dir("${env.PROJECT_NAME}") {
withCredentials([usernamePassword(credentialsId: 'github-bot', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh '''
git add -A
git config user.email "${PROJECT_NAME}-bot@eclipse.org"
git config user.name "${PROJECT_BOT_NAME}"
git commit --allow-empty -m "docs: update documentation ${JOB_NAME}-${BUILD_NUMBER}"
git log --graph --abbrev-commit --date=relative -n 5
git push "https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/eclipse-keypop/${PROJECT_NAME}.git" HEAD:gh-pages
'''
}
}
} }
}
stage('Publish packaging to Eclipse') {
when { expression { deploySnapshot || deployRelease } }
steps { container('java-builder') { sshagent(['projects-storage.eclipse.org-bot-ssh']) { sh 'publish_packaging' } } }
}
}
post { always { container('java-builder') {
archiveArtifacts artifacts: 'build*/libs/**', allowEmptyArchive: true
archiveArtifacts artifacts: 'build*/reports/tests/**', allowEmptyArchive: true
archiveArtifacts artifacts: 'build*/reports/jacoco/test/html/**', allowEmptyArchive: true
} } }
}