There's always another secret

- Parse a build_secrets.properties file provided by CI
- Expand archive glob to include api artifacts
This commit is contained in:
Jozufozu 2025-01-26 17:09:37 -08:00
parent d5963455dc
commit 0288b37b22
2 changed files with 55 additions and 3 deletions

11
Jenkinsfile vendored
View file

@ -23,8 +23,13 @@ pipeline {
stage('Build') {
steps {
echo 'Building project.'
sh './gradlew build publish --stacktrace --warn'
withCredentials([
// build_secrets is parsed in SubprojectExtension#loadSecrets
file(credentialsId: 'build_secrets', variable: 'ORG_GRADLE_PROJECT_secretFile'),
]) {
echo 'Building project.'
sh './gradlew build publish --stacktrace --warn'
}
}
}
}
@ -33,7 +38,7 @@ pipeline {
always {
archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true
archiveArtifacts artifacts: '**/build/libs/**/*.jar', fingerprint: true
withCredentials([
string(credentialsId: 'discord_webhook_url', variable: 'DISCORD_URL')

View file

@ -14,9 +14,14 @@ import org.gradle.jvm.tasks.Jar
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.*
import org.gradle.language.jvm.tasks.ProcessResources
import java.io.File
import java.net.URI
import java.util.*
open class SubprojectExtension(val project: Project) {
fun init(archiveBase: String, group: String, version: String) {
loadSecrets()
setBaseProperties(archiveBase, group, version)
setupJava()
addRepositories()
@ -154,6 +159,48 @@ open class SubprojectExtension(val project: Project) {
if (project.hasProperty("mavendir")) {
maven(project.rootProject.file(project.property("mavendir") as String))
}
// Sets maven credentials if they are provided. This is generally
// only used for external/remote uploads.
if (project.hasProperty("mavenUsername") && project.hasProperty("mavenPassword") && project.hasProperty("mavenURL")) {
maven {
credentials {
username = project.property("mavenUsername") as String
password = project.property("mavenPassword") as String
}
url = URI.create(project.property("mavenURL") as String)
}
}
}
}
private fun loadSecrets() {
// Detects the secrets file provided by CI and loads it into the project properties
if (project.rootProject.hasProperty("secretFile")) {
project.logger.lifecycle("Automatically loading properties from the secretFile")
val secretsFile = project.rootProject.file(project.rootProject.property("secretFile") as String)
if (secretsFile.exists() && secretsFile.name.endsWith(".properties")) {
loadProperties(secretsFile)
}
}
}
private fun loadProperties(propertyFile: File) {
if (propertyFile.exists()) {
val properties = Properties().apply { load(propertyFile.inputStream()) }
var count = 0
for (entry in properties.entries) {
if (entry.key is String) {
project.setProperty(entry.key as String, entry.value)
count++
}
}
project.logger.lifecycle("Successfully loaded $count properties")
} else {
project.logger.warn("The property file ${propertyFile.getName()} could not be loaded. It does not exist.")
}
}
}