-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
122 lines (106 loc) · 5.26 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
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
def COLOR_MAP = ['SUCCESS': 'good', 'FAILURE': 'danger', 'UNSTABLE': 'danger', 'ABORTED': 'danger']
def gradleArgs = "--stacktrace"
def isPublish = BRANCH_NAME == 'publish'
String versionPostfix = BRANCH_NAME
// Note: using Jenkins only for publishing to Central, so only run all stages if triggered manually.
def buildCauses = currentBuild.getBuildCauses()
boolean startedByUser = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause').size() > 0
echo "startedByUser=$startedByUser, build causes: $buildCauses"
// Note: using single quotes to avoid Groovy String interpolation leaking secrets.
def gitlabRepoArgs = '-PgitlabUrl=$GITLAB_URL -PgitlabTokenName=Private-Token -PgitlabToken=$GITLAB_TOKEN'
def gitlabRepoArgsBat = '-PgitlabUrl=%GITLAB_URL% -PgitlabTokenName=Private-Token -PgitlabToken=%GITLAB_TOKEN%'
def uploadRepoArgsCentral = '-PsonatypeUsername=$OSSRH_LOGIN_USR -PsonatypePassword=$OSSRH_LOGIN_PSW'
pipeline {
// It should be "agent none", but googlechatnotification requires a agent (bug?).
// As a workaround we use label 'gchat' instead; don't use a agent used for stages here as it can deadlock.
agent { label 'gchat' }
environment {
GITLAB_URL = credentials('gitlab_url')
GITLAB_TOKEN = credentials('GITLAB_TOKEN_ALL')
// Note: can't set key file here as it points to path, which must be agent-specific.
ORG_GRADLE_PROJECT_signingKeyId = credentials('objectbox_signing_key_id')
ORG_GRADLE_PROJECT_signingPassword = credentials('objectbox_signing_key_password')
}
stages {
stage ('build') {
when { expression { startedByUser } }
parallel {
stage('build-linux') {
agent { label 'linux' }
steps {
sh 'chmod +x gradlew'
sh "./gradlew -version"
sh "./gradlew $gradleArgs $gitlabRepoArgs clean check"
}
post {
always {
junit '**/build/test-results/**/TEST-*.xml'
}
}
}
stage('build-windows') {
agent { label 'windows' }
steps {
bat "gradlew -version"
bat "gradlew $gradleArgs $gitlabRepoArgsBat clean check"
}
post {
always {
junit '**/build/test-results/**/TEST-*.xml'
}
}
}
}
}
stage('upload-to-internal') {
when { expression { startedByUser } }
agent { label 'linux' }
environment {
// Note: for key use Jenkins secret file with PGP key as text in ASCII-armored format.
ORG_GRADLE_PROJECT_signingKeyFile = credentials('objectbox_signing_key')
}
steps {
sh "./gradlew $gradleArgs $gitlabRepoArgs -PversionPostFix=$versionPostfix publishMavenJavaPublicationToGitLabRepository"
}
}
stage('upload-to-central') {
// Note: publishing to Central has moved to GitLab.
when { expression { return isPublish && startedByUser } }
agent { label 'linux' }
environment {
// Note: for key use Jenkins secret file with PGP key as text in ASCII-armored format.
ORG_GRADLE_PROJECT_signingKeyFile = credentials('objectbox_signing_key')
OSSRH_LOGIN = credentials('ossrh-login')
}
steps {
googlechatnotification url: 'id:gchat_java',
message: "*Publishing* ${currentBuild.fullDisplayName} to Central...\n${env.BUILD_URL}"
sh "./gradlew $gradleArgs $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}"
}
}
}
post {
// For global vars see /jenkins/pipeline-syntax/globals
always {
googlechatnotification url: 'id:gchat_java', message: "${currentBuild.currentResult}: ${currentBuild.fullDisplayName}\n${env.BUILD_URL}",
notifyFailure: 'true', notifyUnstable: 'true', notifyBackToNormal: 'true'
}
failure {
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}
"""
)
}
}
}