Skip to content

Commit dc90603

Browse files
committed
JAVA-2348: Use ORG_GRADLE_PROJECT-prefixed environment variable to pass project properties to Gradle
1 parent 805de7c commit dc90603

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

.evergreen/.evg.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,11 @@ functions:
229229
- command: shell.exec
230230
type: test
231231
params:
232+
silent: true
232233
working_dir: "src"
233234
script: |
234-
PROJECT_DIRECTORY=${PROJECT_DIRECTORY} NEXUS_USER=${sonatype_username} NEXUS_PWD=${sonatype_password} SIGNING_PWD=${signing_password} SIGNING_KEY_ID=${signing_keyId} RING_FILE_GPG_BASE64=${ring_file_gpg_base64} .evergreen/publish.sh
235+
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
236+
PROJECT_DIRECTORY=${PROJECT_DIRECTORY} NEXUS_USERNAME=${nexus_username} NEXUS_PASSWORD=${nexus_password} SIGNING_PASSWORD=${signing_password} SIGNING_KEY_ID=${signing_keyId} RING_FILE_GPG_BASE64=${ring_file_gpg_base64} .evergreen/publish.sh
235237
236238
"cleanup":
237239
- command: shell.exec

.evergreen/publish.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,12 @@ echo ${RING_FILE_GPG_BASE64} | base64 -d > ${PROJECT_DIRECTORY}/secring.gpg
1313
echo "Publishing snapshot with jdk8"
1414

1515
export JAVA_HOME="/opt/java/jdk8"
16+
17+
export ORG_GRADLE_PROJECT_nexusUsername=${NEXUS_USERNAME}
18+
export ORG_GRADLE_PROJECT_nexusPassword=${NEXUS_PASSWORD}
19+
export ORG_GRADLE_PROJECT_signing_keyId=${SIGNING_KEY_ID}
20+
export ORG_GRADLE_PROJECT_signing_password=${SIGNING_PASSWORD}
21+
export ORG_GRADLE_PROJECT_signing_secretKeyRingFile=${PROJECT_DIRECTORY}/secring.gpg
22+
1623
./gradlew -version
17-
./gradlew -PnexusUsername=${NEXUS_USER} -PnexusPassword=${NEXUS_PWD} -Psigning.secretKeyRingFile=${PROJECT_DIRECTORY}/secring.gpg -Psigning.password=${SIGNING_PWD} -Psigning.keyId=${SIGNING_KEY_ID} uploadSnapshotArchives --info
24+
./gradlew uploadSnapshotArchives

build.gradle

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ configure(subprojects.findAll { it.name != 'util' }) {
7373
project.hasProperty(propertyName) && project.property(propertyName).toBoolean()
7474
}
7575

76+
/*
77+
For security we allow the signing-related project properties to be passed in as environment variables, which
78+
Gradle enables if they are prefixed with "ORG_GRADLE_PROJECT_". But since environment variables can not contain
79+
the '.' character and the signing-related properties contain '.', here we map signing-related project properties with '_'
80+
to ones with '.' that are expected by the signing plugin.
81+
*/
82+
gradle.taskGraph.whenReady { taskGraph ->
83+
if (taskGraph.allTasks.any { it instanceof Sign }) {
84+
if (project.hasProperty("signing_keyId")) {
85+
allprojects { ext."signing.keyId" = project.property("signing_keyId") }
86+
}
87+
if (project.hasProperty("signing_secretKeyRingFile")) {
88+
allprojects { ext."signing.secretKeyRingFile" = project.property("signing_secretKeyRingFile") }
89+
}
90+
if (project.hasProperty("signing_password")) {
91+
allprojects { ext."signing.password" = project.property("signing_password") }
92+
}
93+
}
94+
}
95+
7696
javadoc {
7797
exclude "**/com/mongodb/**/internal/**"
7898

0 commit comments

Comments
 (0)