Skip to content

Commit 3eec172

Browse files
Jenkinsfile: re-add versionPostFix, use variables for repo args.
Follow-up to Jenkins: prevent Groovy String interpolation leaking secrets.
1 parent cdc1378 commit 3eec172

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

Jenkinsfile

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ String gradleArgs = '-Dorg.gradle.daemon=false --stacktrace'
66
boolean isPublish = BRANCH_NAME == 'publish'
77
String versionPostfix = isPublish ? '' : BRANCH_NAME // Build script detects empty string as not set.
88

9+
// Note: using single quotes to avoid Groovy String interpolation leaking secrets.
10+
def internalRepoArgs = '-PinternalObjectBoxRepo=$MVN_REPO_URL ' +
11+
'-PinternalObjectBoxRepoUser=$MVN_REPO_LOGIN_USR ' +
12+
'-PinternalObjectBoxRepoPassword=$MVN_REPO_LOGIN_PSW'
13+
def uploadRepoArgs = '-PpreferredRepo=$MVN_REPO_UPLOAD_URL ' +
14+
'-PpreferredUsername=$MVN_REPO_LOGIN_USR ' +
15+
'-PpreferredPassword=$MVN_REPO_LOGIN_PSW '
16+
// Note: add quotes around URL parameter to avoid line breaks due to semicolon in URL.
17+
def uploadRepoArgsBintray = '\"-PpreferredRepo=$BINTRAY_URL\" ' +
18+
'-PpreferredUsername=$BINTRAY_LOGIN_USR ' +
19+
'-PpreferredPassword=$BINTRAY_LOGIN_PSW'
20+
921
// https://jenkins.io/doc/book/pipeline/syntax/
1022
pipeline {
1123
agent { label 'java' }
@@ -14,15 +26,7 @@ pipeline {
1426
GITLAB_URL = credentials('gitlab_url')
1527
MVN_REPO_LOGIN = credentials('objectbox_internal_mvn_user')
1628
MVN_REPO_URL = credentials('objectbox_internal_mvn_repo_http')
17-
// Warning: use single quotes to avoid Groovy String interpolation leaking secrets.
18-
MVN_REPO_ARGS = '-PinternalObjectBoxRepo=$MVN_REPO_URL ' +
19-
'-PinternalObjectBoxRepoUser=$MVN_REPO_LOGIN_USR ' +
20-
'-PinternalObjectBoxRepoPassword=$MVN_REPO_LOGIN_PSW'
2129
MVN_REPO_UPLOAD_URL = credentials('objectbox_internal_mvn_repo')
22-
MVN_REPO_UPLOAD_ARGS = '-PpreferredRepo=$MVN_REPO_UPLOAD_URL ' +
23-
'-PpreferredUsername=$MVN_REPO_LOGIN_USR ' +
24-
'-PpreferredPassword=$MVN_REPO_LOGIN_PSW ' +
25-
'-PversionPostFix=$versionPostfix'
2630
// Note: for key use Jenkins secret file with PGP key as text in ASCII-armored format.
2731
ORG_GRADLE_PROJECT_signingKeyFile = credentials('objectbox_signing_key')
2832
ORG_GRADLE_PROJECT_signingKeyId = credentials('objectbox_signing_key_id')
@@ -55,7 +59,7 @@ pipeline {
5559

5660
stage('build-java') {
5761
steps {
58-
sh "./ci/test-with-asan.sh $gradleArgs $MVN_REPO_ARGS -Dextensive-tests=true clean test " +
62+
sh "./ci/test-with-asan.sh $gradleArgs $internalRepoArgs -Dextensive-tests=true clean test " +
5963
"--tests io.objectbox.FunctionalTestSuite " +
6064
"--tests io.objectbox.test.proguard.ObfuscatedEntityTest " +
6165
"--tests io.objectbox.rx.QueryObserverTest " +
@@ -66,7 +70,7 @@ pipeline {
6670

6771
stage('upload-to-internal') {
6872
steps {
69-
sh "./gradlew $gradleArgs $MVN_REPO_ARGS $MVN_REPO_UPLOAD_ARGS uploadArchives"
73+
sh "./gradlew $gradleArgs $internalRepoArgs $uploadRepoArgs -PversionPostFix=$versionPostfix uploadArchives"
7074
}
7175
}
7276

@@ -80,12 +84,8 @@ pipeline {
8084
googlechatnotification url: 'id:gchat_java',
8185
message: "*Publishing* ${currentBuild.fullDisplayName} to Bintray...\n${env.BUILD_URL}"
8286

83-
// Note: supply internal Maven repo as tests use native dependencies (can't publish those without the Java libraries).
84-
// Note: add quotes around URL parameter to avoid line breaks due to semicolon in URL.
85-
// Warning: use single quotes to avoid Groovy String interpolation leaking secrets.
86-
sh "./gradlew $gradleArgs $MVN_REPO_ARGS " +
87-
'\"-PpreferredRepo=$BINTRAY_URL\" -PpreferredUsername=$BINTRAY_LOGIN_USR -PpreferredPassword=$BINTRAY_LOGIN_PSW ' +
88-
'uploadArchives'
87+
// Note: supply internal repo as tests use native dependencies that might not be published, yet.
88+
sh "./gradlew $gradleArgs $internalRepoArgs $uploadRepoArgsBintray uploadArchives"
8989

9090
googlechatnotification url: 'id:gchat_java',
9191
message: "Published ${currentBuild.fullDisplayName} successfully to Bintray - check https://bintray.com/objectbox/objectbox\n${env.BUILD_URL}"

ci/Jenkinsfile-Windows

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ String buildsToKeep = '500'
22

33
String gradleArgs = '-Dorg.gradle.daemon=false --stacktrace'
44

5+
// Note: using single quotes to avoid Groovy String interpolation leaking secrets.
6+
def internalRepoArgsBat = '-PinternalObjectBoxRepo=%MVN_REPO_URL% ' +
7+
'-PinternalObjectBoxRepoUser=%MVN_REPO_LOGIN_USR% ' +
8+
'-PinternalObjectBoxRepoPassword=%MVN_REPO_LOGIN_PSW%'
9+
510
// https://jenkins.io/doc/book/pipeline/syntax/
611
pipeline {
712
agent { label 'windows' }
@@ -10,10 +15,6 @@ pipeline {
1015
GITLAB_URL = credentials('gitlab_url')
1116
MVN_REPO_URL = credentials('objectbox_internal_mvn_repo_http')
1217
MVN_REPO_LOGIN = credentials('objectbox_internal_mvn_user')
13-
// Warning: use single quotes to avoid Groovy String interpolation leaking secrets.
14-
MVN_REPO_ARGS = '-PinternalObjectBoxRepo=%MVN_REPO_URL% ' +
15-
'-PinternalObjectBoxRepoUser=%MVN_REPO_LOGIN_USR% ' +
16-
'-PinternalObjectBoxRepoPassword=%MVN_REPO_LOGIN_PSW%'
1718
}
1819

1920
options {
@@ -38,7 +39,7 @@ pipeline {
3839
// Remove files to avoid archiving them again.
3940
bat 'del /q /s hs_err_pid*.log'
4041

41-
bat "gradlew $gradleArgs $MVN_REPO_ARGS cleanTest build test"
42+
bat "gradlew $gradleArgs $internalRepoArgsBat cleanTest build test"
4243
}
4344
post {
4445
always {
@@ -57,7 +58,7 @@ pipeline {
5758
// 32-bit ObjectBox to run tests (see build.gradle file).
5859
// Note: assumes JAVA_HOME_X86 is set to 32-bit JDK path.
5960
// Note: no space before && or value has space as well.
60-
bat "set TEST_WITH_JAVA_X86=true&& gradlew $gradleArgs $MVN_REPO_ARGS cleanTest build test"
61+
bat "set TEST_WITH_JAVA_X86=true&& gradlew $gradleArgs $internalRepoArgsBat cleanTest build test"
6162
}
6263
post {
6364
always {

0 commit comments

Comments
 (0)