Deployment Implementation
import com.here.platform.ci.*
def setJobParametersRecursively(pipeline_id) {
properties([
parameters([
string(defaultValue: pipeline_id,
description: "This is the ID of the production " +
"pipeline to which a successfully tested application " +
"will be deployed",
name: 'PIPELINE_ID',
trim: true),
string(defaultValue: env.OLP_CREDENTIALS_FILE_ID,
name: 'OLP_CREDENTIALS_FILE_ID',
trim: true),
string(defaultValue: env.SETTINGS_XML_FILE_ID,
name: 'SETTINGS_XML_FILE_ID',
trim: true),
])
])
}
def node_label = env.NODE_LABEL ? env.NODE_LABEL : 'master'
node(node_label) {
def MAVEN_OPTS = "-B -q -s \$MAVEN_SETTINGS"
CLIHelper cli = new CLIHelper(this)
withCredentials([file(credentialsId: env.OLP_CREDENTIALS_FILE_ID, variable: 'OLP_CREDENTIALS')]) {
configFileProvider([configFile(fileId: env.SETTINGS_XML_FILE_ID, variable: 'MAVEN_SETTINGS')]) {
try {
GString artifact = "${env.PROJECT_GROUP_ID}:${env.PROJECT_ARTIFACT_ID}:${env.PROJECT_VERSION}:jar"
String deploymentId = "prd"
GString path_prefix = "${WORKSPACE}/target/dependency/deployments/"
GString deployment_config_path = "${path_prefix}/${deploymentId}/deployment.properties"
def deployment
def pipeline_id
def current_version_id
def version_id
def pipeline_config_path
stage('Initialize') {
cleanWs()
def dependencyPlugin = "org.apache.maven.plugins:maven-dependency-plugin:3.1.1"
sh("mvn ${MAVEN_OPTS} ${dependencyPlugin}:unpack -Dartifact=${artifact} -Dproject.basedir=${WORKSPACE}")
sh("mvn ${MAVEN_OPTS} ${dependencyPlugin}:copy -Dartifact=${artifact}:platform -Dproject.basedir=${WORKSPACE}")
deployment = readProperties(file: deployment_config_path)
cli.getOlpCliFromSDK(deployment.sdk_version)
}
stage('Deploy pipeline') {
pipeline_config_path = "${path_prefix}/pipeline-config.conf"
pipeline_config = cli.preparePipelineConfig(pipeline_config_path, path_prefix, deployment)
def fat_jar_path = FileHelper.findFile(this, "**/*-platform.jar")
if (env.PIPELINE_ID) {
deployment.put("pipeline_id", env.PIPELINE_ID)
}
def result = cli.deployPipeline(deployment, fat_jar_path, pipeline_config_path)
pipeline_id = result.pipeline_id
version_id = result.version_id
if (!env.PIPELINE_ID) {
setJobParametersRecursively(pipeline_id)
}
}
stage("Activate/upgrade pipeline") {
def all_pipeline_versions =
cli.json("olp pipeline version list ${pipeline_id}").pipelineVersions
current_version_id = cli.getCurrentVersionId(all_pipeline_versions)
if (current_version_id == '') {
cli.run(
"olp pipeline version activate "
+ "${pipeline_id} ${version_id}")
} else {
cli.run(
"olp pipeline version upgrade ${pipeline_id}"
+ "--from ${current_version_id} --to ${version_id}")
}
}
} catch (error) {
stage("Clean-up") {
cli.cleanUp()
}
throw error
}
}
}
}