mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-30 23:04:57 +01:00
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:
parent
d5963455dc
commit
0288b37b22
2 changed files with 55 additions and 3 deletions
7
Jenkinsfile
vendored
7
Jenkinsfile
vendored
|
@ -23,17 +23,22 @@ pipeline {
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
|
|
||||||
steps {
|
steps {
|
||||||
|
withCredentials([
|
||||||
|
// build_secrets is parsed in SubprojectExtension#loadSecrets
|
||||||
|
file(credentialsId: 'build_secrets', variable: 'ORG_GRADLE_PROJECT_secretFile'),
|
||||||
|
]) {
|
||||||
echo 'Building project.'
|
echo 'Building project.'
|
||||||
sh './gradlew build publish --stacktrace --warn'
|
sh './gradlew build publish --stacktrace --warn'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
|
|
||||||
always {
|
always {
|
||||||
|
|
||||||
archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true
|
archiveArtifacts artifacts: '**/build/libs/**/*.jar', fingerprint: true
|
||||||
|
|
||||||
withCredentials([
|
withCredentials([
|
||||||
string(credentialsId: 'discord_webhook_url', variable: 'DISCORD_URL')
|
string(credentialsId: 'discord_webhook_url', variable: 'DISCORD_URL')
|
||||||
|
|
|
@ -14,9 +14,14 @@ import org.gradle.jvm.tasks.Jar
|
||||||
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
||||||
import org.gradle.kotlin.dsl.*
|
import org.gradle.kotlin.dsl.*
|
||||||
import org.gradle.language.jvm.tasks.ProcessResources
|
import org.gradle.language.jvm.tasks.ProcessResources
|
||||||
|
import java.io.File
|
||||||
|
import java.net.URI
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
open class SubprojectExtension(val project: Project) {
|
open class SubprojectExtension(val project: Project) {
|
||||||
fun init(archiveBase: String, group: String, version: String) {
|
fun init(archiveBase: String, group: String, version: String) {
|
||||||
|
loadSecrets()
|
||||||
|
|
||||||
setBaseProperties(archiveBase, group, version)
|
setBaseProperties(archiveBase, group, version)
|
||||||
setupJava()
|
setupJava()
|
||||||
addRepositories()
|
addRepositories()
|
||||||
|
@ -154,6 +159,48 @@ open class SubprojectExtension(val project: Project) {
|
||||||
if (project.hasProperty("mavendir")) {
|
if (project.hasProperty("mavendir")) {
|
||||||
maven(project.rootProject.file(project.property("mavendir") as String))
|
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.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue