All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.nemerosa.ontrack.extension.jenkins.autoversioning.JenkinsPostProcessingConfig.kt Maven / Gradle / Ivy

package net.nemerosa.ontrack.extension.jenkins.autoversioning

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.ObjectNode
import net.nemerosa.ontrack.json.asJson
import net.nemerosa.ontrack.json.parse

/**
 * Configuration for the [JenkinsPostProcessing] service.
 *
 * @property dockerImage Docker image defining the environment
 * @property dockerCommand Command to run in the working copy inside the Docker container
 * @property commitMessage Commit message for the post processed files. If not defined, a default message will be provided
 * @property config Jenkins configuration to use for the connection (optional, using defaults if not specified)
 * @property job Path to the job to launch for the post processing (optional, using defaults if not specified)
 * @property credentials List of credentials to inject in the command
 */
data class JenkinsPostProcessingConfig(
    val dockerImage: String,
    val dockerCommand: String,
    val commitMessage: String? = null,
    val config: String? = null,
    val job: String? = null,
    val credentials: List? = null,
) {

    companion object {
        fun parseJson(config: JsonNode): JenkinsPostProcessingConfig {
            // Switching between short & expanded format for the credentials
            val credentials: JsonNode = config.path(JenkinsPostProcessingConfig::credentials.name)
            return if (credentials.isMissingNode || credentials.isNull || credentials.isArray) {
                // Standard parsing
                config.parse()
            } else if (credentials.isTextual) {
                // Parsing the credentials from text
                val credentialsList = JenkinsPostProcessingConfigCredentials.parseLines(credentials.asText())
                (config as ObjectNode).set(
                    JenkinsPostProcessingConfig::credentials.name,
                    credentialsList.asJson()
                )
                // Parsing
                config.parse()
            } else {
                error("Jenkins auto versioning config credentials format error: ${credentials}")
            }
        }
    }

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy