pipeline {
    agent any
    stages {
        stage('Load Library') {
            steps {
                // Load library to regenerate documentation in Global Variables Reference in the Jenkins UI
                // Note we have to explicitly specify a retriever in order for this to work for PR builds from forks
                library identifier: "jenkins-global-libraries@${env.GIT_COMMIT}", retriever: modernSCM([
                    $class: 'GitSCMSource',
                    remote: "git@github.com:${env.CHANGE_FORK ?: 'theorchard'}/jenkins-global-libraries.git",
                    credentialsId: '577cbc72-7d9e-4eba-924c-ecbbe6de9805']
                )
            }
        }
        stage('Unit Tests') {
            steps {
                withGradle {
                    sh './gradlew test'
                }
            }
            post {
                always {
                    junit 'build/test-results/test/*.xml'
                }
            }
        }
    }
}
