/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

@Library('jenkins-pipeline-shared-libraries')_

pr_check_script = null

pipeline {
    agent {
        label util.avoidFaultyNodes('ubuntu')
    }
    options {
        timestamps()
        timeout(time: 360, unit: 'MINUTES')
        disableConcurrentBuilds(abortPrevious: true)
    }
    environment {
        BUILDCHAIN_PROJECT = 'apache/incubator-kie-optaplanner'
        BUILDCHAIN_CONFIG_REPO = 'incubator-kie-optaplanner'
        BUILDCHAIN_CONFIG_FILE_PATH = '.ci/buildchain-config-pr-cdb.yaml'

        ENABLE_SONARCLOUD = 'false'
        SONAR_PROJECT_KEY = 'apache_incubator-kie-optaplanner'
        OPTAPLANNER_BUILD_MVN_OPTS = '-Prun-code-coverage'
    }
    stages {
        stage('Initialize') {
            steps {
                script {
                    // load `pr_check.groovy` file from kogito-pipelines:main
                    dir('kogito-pipelines') {
                        checkout(githubscm.resolveRepository('incubator-kie-kogito-pipelines', 'apache', 'main', false, 'ASF_Cloudbees_Jenkins_ci-builds'))
                        pr_check_script = load 'dsl/scripts/pr_check.groovy'
                    }
                }
            }
        }
        stage('PR check') {
            steps {
                script {
                    dir('kogito-pipelines') {
                        pr_check_script.launch()
                    }
                }
            }
        }
    }
    post {
        cleanup {
            cleanWs()
        }
    }
}
