forked from objectbox/objectbox-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
166 lines (146 loc) · 7.14 KB
/
Copy pathJenkinsfile
File metadata and controls
166 lines (146 loc) · 7.14 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// dev branch only: every 30 minutes at night (1:00 - 5:00)
String cronSchedule = BRANCH_NAME == 'dev' ? '*/30 1-5 * * *' : ''
String buildsToKeep = '500'
String gradleArgs = '--stacktrace'
boolean isPublish = BRANCH_NAME == 'publish'
String versionPostfix = isPublish ? '' : BRANCH_NAME // Build script detects empty string as not set.
// Note: using single quotes to avoid Groovy String interpolation leaking secrets.
def signingArgs = '-PsigningKeyFile=$SIGNING_FILE -PsigningKeyId=$SIGNING_ID -PsigningPassword=$SIGNING_PWD'
def gitlabRepoArgs = '-PgitlabUrl=$GITLAB_URL -PgitlabPrivateToken=$GITLAB_TOKEN'
def uploadRepoArgsCentral = '-PsonatypeUsername=$OSSRH_LOGIN_USR -PsonatypePassword=$OSSRH_LOGIN_PSW'
boolean startedByTimer = currentBuild.getBuildCauses('hudson.triggers.TimerTrigger$TimerTriggerCause').size() > 0
def buildCauses = currentBuild.getBuildCauses()
echo "startedByTimer=$startedByTimer, build causes: $buildCauses"
// https://jenkins.io/doc/book/pipeline/syntax/
pipeline {
agent { label 'java' }
environment {
GITLAB_URL = credentials('gitlab_url')
GITLAB_TOKEN = credentials('GITLAB_TOKEN_ALL')
GITLAB_INTEG_TESTS_TRIGGER_URL = credentials('gitlab-trigger-java-integ-tests')
// Note: for key use Jenkins secret file with PGP key as text in ASCII-armored format.
SIGNING_FILE = credentials('objectbox_signing_key')
SIGNING_ID = credentials('objectbox_signing_key_id')
SIGNING_PWD = credentials('objectbox_signing_key_password')
}
options {
buildDiscarder(logRotator(numToKeepStr: buildsToKeep, artifactNumToKeepStr: buildsToKeep))
timeout(time: 1, unit: 'HOURS') // If build hangs (regular build should be much quicker)
gitLabConnection('objectbox-gitlab-connection')
}
triggers {
upstream(upstreamProjects: "ObjectBox-Linux/${env.BRANCH_NAME.replaceAll("/", "%2F")}",
threshold: hudson.model.Result.SUCCESS)
cron(cronSchedule)
}
stages {
stage('init') {
steps {
sh './gradlew -version'
// "|| true" for an OK exit code if no file is found
sh 'rm tests/objectbox-java-test/hs_err_pid*.log || true'
}
}
stage('build-java') {
steps {
sh "./ci/test-with-asan.sh $gradleArgs $signingArgs $gitlabRepoArgs clean build"
}
post {
always {
junit '**/build/test-results/**/TEST-*.xml'
archiveArtifacts artifacts: 'tests/*/hs_err_pid*.log', allowEmptyArchive: true // Only on JVM crash.
recordIssues(tool: spotBugs(pattern: '**/build/reports/spotbugs/*.xml', useRankAsPriority: true))
}
}
}
stage("test-jdks") {
matrix {
axes {
axis {
name "TEST_JDK"
values "8", "16"
}
}
stages {
stage("test") {
// Set agent to start with new workspace to avoid Gradle compile issues on shared workspace
agent {
label 'java'
}
environment {
TEST_JDK = "${TEST_JDK}"
}
steps {
// "|| true" for an OK exit code if no file is found
sh 'rm tests/objectbox-java-test/hs_err_pid*.log || true'
// Note: do not run check task as it includes SpotBugs.
sh "./ci/test-with-asan.sh $gradleArgs $gitlabRepoArgs clean :tests:objectbox-java-test:test"
}
post {
always {
junit '**/build/test-results/**/TEST-*.xml'
archiveArtifacts artifacts: 'tests/*/hs_err_pid*.log', allowEmptyArchive: true // Only on JVM crash.
}
}
}
}
}
}
stage('upload-to-internal') {
steps {
sh "./gradlew $gradleArgs $signingArgs $gitlabRepoArgs -PversionPostFix=$versionPostfix publishMavenJavaPublicationToGitLabRepository"
}
}
stage('upload-to-central') {
when { expression { return isPublish } }
environment {
OSSRH_LOGIN = credentials('ossrh-login')
}
steps {
googlechatnotification url: 'id:gchat_java',
message: "*Publishing* ${currentBuild.fullDisplayName} to Central...\n${env.BUILD_URL}"
// Note: supply internal repo as tests use native dependencies that might not be published, yet.
sh "./gradlew $gradleArgs $signingArgs $gitlabRepoArgs $uploadRepoArgsCentral publishMavenJavaPublicationToSonatypeRepository closeAndReleaseStagingRepository"
googlechatnotification url: 'id:gchat_java',
message: "Published ${currentBuild.fullDisplayName} successfully to Central - check https://repo1.maven.org/maven2/io/objectbox/ in a few minutes.\n${env.BUILD_URL}"
}
}
}
// For global vars see /jenkins/pipeline-syntax/globals
post {
always {
googlechatnotification url: 'id:gchat_java', message: "${currentBuild.currentResult}: ${currentBuild.fullDisplayName}\n${env.BUILD_URL}",
notifyFailure: 'true', notifyUnstable: 'true', notifyBackToNormal: 'true'
}
failure {
updateGitlabCommitStatus name: 'build', state: 'failed'
emailext (
subject: "${currentBuild.currentResult}: ${currentBuild.fullDisplayName}",
mimeType: 'text/html',
recipientProviders: [[$class: 'DevelopersRecipientProvider']],
body: """
<p>${currentBuild.currentResult}:
<a href='${env.BUILD_URL}'>${currentBuild.fullDisplayName}</a>
(<a href='${env.BUILD_URL}/console'>console</a>)
</p>
<p>Git: ${GIT_COMMIT} (${GIT_BRANCH})
<p>Build time: ${currentBuild.durationString}
"""
)
}
success {
updateGitlabCommitStatus name: 'build', state: 'success'
script {
if (startedByTimer) {
echo "Started by timer, not triggering integration tests"
} else {
// Trigger integration tests in GitLab
// URL configured like <host>/api/v4/projects/<id>/trigger/pipeline?token=<token>
// Note: do not fail on error in case ref does not exist, only output response
// --silent --show-error disable progress output but still show errors
sh 'curl --silent --show-error -X POST "$GITLAB_INTEG_TESTS_TRIGGER_URL&ref=$GIT_BRANCH"'
}
}
}
}
}