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

pr_check_script = null

pipeline {
    agent {
        label util.avoidFaultyNodes('ubuntu')
    }
    options {
        timestamps()
        timeout(time: 480, unit: 'MINUTES')
        disableConcurrentBuilds(abortPrevious: true)
        skipDefaultCheckout()
    }
    environment {
        BUILDCHAIN_PROJECT = 'apache/incubator-kie-kogito-apps'

        ENABLE_SONARCLOUD = 'false'
        SONAR_PROJECT_KEY = 'apache_incubator-kie-kogito-apps'
        KOGITO_APPS_BUILD_MVN_OPTS = '-Dvalidate-formatting -Prun-code-coverage'
    }
    stages {
        stage('Initialize') {
            steps {
                cleanWs(disableDeferredWipeout: true)
                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()
        }
    }
}
