Validation Implementation

#!groovy

/*--------------------------------------------------------------------------------------------------
 *
 * Copyright (C) 2018, HERE Global B.V.
 *
 * These coded instructions, statements, and computer programs contain
 * unpublished proprietary information of HERE Global B.V., and are copy
 * protected by law. They may not be disclosed to third parties or copied
 * or duplicated in any form, in whole or in part, without the specific,
 * prior written permission of HERE Global B.V.
 *
 *--------------------------------------------------------------------------------------------------
 */

import com.here.platform.ci.*

/**
 *
 * ID:s of multiple configuration files from here https://${JENKINS_URL}/configfiles/index
 *
 * @env [OLP_CREDENTIALS_FILE_ID] (e.g. ${USER_HOME}/.here/credentials.properties)
 * @env [SETTINGS_XML_FILE_ID] (e.g. ${USER_HOME}/.m2/settings.xml)
 * @env [NODE_LABEL] (optional) Jenkins label or node name. By default 'master'.
 *
 * Note:
 * ${JENKINS_URL} should be replaced with your own Jenkins URL.
 */

def node_label = env.NODE_LABEL ? env.NODE_LABEL : 'master'

node(node_label) {
    def MAVEN_OPTS = "-B -q -s \$MAVEN_SETTINGS"
    // HERE platform Delivery Jenkins DSL Shared Library
    CLIHelper cli = new CLIHelper(this)

    withCredentials([file(credentialsId: env.OLP_CREDENTIALS_FILE_ID, variable: 'OLP_CREDENTIALS')]) {
        configFileProvider([configFile(fileId: env.MAVEN_SETTINGS_FILE_ID, variable: 'MAVEN_SETTINGS')]) {
            try {
                String artifact = "${env.PROJECT_GROUP_ID}:${env.PROJECT_ARTIFACT_ID}:${env.PROJECT_VERSION}:jar"
                String deploymentId = "test"
                String path_prefix = "${WORKSPACE}/target/dependency/deployments/"
                String deployment_config_path = "${path_prefix}/${deploymentId}/deployment.properties"
                def deployment
                def pipeline_id
                def version_id
                def pipeline_config_path
                def pipeline_config

                stage('Initialize') {
                    // Clean workspace before build starts
                    cleanWs()

                    // Get 'fat' JAR package which contains all the dependencies
                    // If build was triggered by upstream build then no parameters are needed
                    def dependencyPlugin = "org.apache.maven.plugins:maven-dependency-plugin:3.1.1"
                    // This is necessary to access a deployment description
                    sh("mvn ${MAVEN_OPTS} ${dependencyPlugin}:unpack -Dartifact=${artifact}:platform -Dproject.basedir=${WORKSPACE}")
                    sh("mvn ${MAVEN_OPTS} ${dependencyPlugin}:copy -Dartifact=${artifact}:platform -Dproject.basedir=${WORKSPACE}")

                    sh("mvn ${MAVEN_OPTS} ${dependencyPlugin}:unpack -Dartifact=${artifact}:it-tests -Dproject.basedir=${WORKSPACE}/test_data")
                    sh("mvn ${MAVEN_OPTS} ${dependencyPlugin}:copy -Dartifact=${artifact}:it-tests -Dproject.basedir=${WORKSPACE}")

                    // Load properties
                    deployment = readProperties(file: deployment_config_path)
                    deployment.put("suffix", "-${env.BUILD_NUMBER}")

                    // Download HERE SDK and and unpack CLI it to ${WORKSPACE}/target/dependency/
                    cli.getOlpCliFromSDK(deployment.sdk_version)
                }

                stage('Prepare test catalogs') {
                    pipeline_config_path = "${path_prefix}/pipeline-config.conf"
                    pipeline_config = cli.preparePipelineConfig(pipeline_config_path, path_prefix, deployment)

                    def input_partition_id = "1475716_20180522155459_20180522153926_20180522155455_10." +
                            "_48.159957275016836_48.080087029569135_12.040017134498243_11.896950104895032"
                    def input_partition_file_path = "${WORKSPACE}/test_data/target/dependency/${input_partition_id}"
                    def partitionID = FileHelper.replaceDateInFileName(input_partition_id)

                    def layer = "sdii-data-archive"
                    def partitions_str = "${partitionID}:${input_partition_file_path}"
                    cli.run(
                            "olp catalog layer partition put ${pipeline_config["archive-catalog"]} ${layer} "
                                    + "--partitions " + partitions_str)
                }

                stage('Create and deploy pipeline') {
                    def fat_jar_path = FileHelper.findFile(this, "**/*-platform.jar")
                    def result = cli.deployPipeline(deployment, fat_jar_path, pipeline_config_path)
                    pipeline_id = result.pipeline_id
                    version_id = result.version_id
                }

                stage("Activate pipeline") {
                    cli.json(
                            "olp pipeline version activate "
                                    + "${pipeline_id} ${version_id} ${cli.optional("", deployment.pipeline_activate_options)} ")
                }

                stage("Wait for pipeline completion") {
                    def timeoutSeconds = 3000
                    cli.json(
                            "olp pipeline version wait --job-state completed "
                                    + "${pipeline_id} ${version_id} "
                                    + "--timeout ${timeoutSeconds} "
                    )
                }

                stage('Run Product Acceptance Tests') {
                    def output_partition = "23611423"

                    cli.run(
                            "olp catalog layer partition get "
                                    + "${pipeline_config["output"]} data-learnings "
                                    + "--partitions ${output_partition} --output ${env.WORKSPACE} ")

                    // Run tests
                    def tests_jar_path = FileHelper.findFile(this, "**/*-it-tests.jar")
                    sh("java -jar -Dpartition=${WORKSPACE}/${output_partition} ${tests_jar_path}")
                }

                stage('Deploy to production environment') {
                    build(
                            job: 'CI-CD-examples/step3',
                            parameters: [
                                    [
                                            $class: 'StringParameterValue',
                                            name  : 'PROJECT_VERSION',
                                            value : env.PROJECT_VERSION
                                    ],
                                    [
                                            $class: 'StringParameterValue',
                                            name  : 'PROJECT_GROUP_ID',
                                            value : env.PROJECT_GROUP_ID
                                    ],
                                    [
                                            $class: 'StringParameterValue',
                                            name  : 'PROJECT_ARTIFACT_ID',
                                            value : env.PROJECT_ARTIFACT_ID
                                    ]
                            ],
                            wait: false
                    )
                }
            } finally {
                stage("Clean-up") {
                    cli.cleanUp()
                }
            }
        }
    }
}

results matching ""

    No results matching ""