#!groovy
// Jenkinsfile (Pipeline Script)

pipeline {
    agent any

    tools {
        jdk 'jdk-11'
    }

    environment {
        gradleParams = "-Pversion=1.0.${BUILD_NUMBER}" // --no-daemon
    }

    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }

        stage('Build') {
            steps{
                withGradle {
                    sh "chmod +x ./gradlew"
                    sh "./gradlew ${gradleParams} -x test clean build"
                }
            }
        }

        stage('Test') {
            steps {
                withGradle {
                    sh "./gradlew ${gradleParams} test"
                }
            }
        }

        stage('Deploy') {
            steps {
                withGradle {
                    configFileProvider([configFile(fileId: '70cb2022-0bc2-4b25-98a4-e1526dbf2735')]) {
                        sh 'GPG_TTY=$(tty) ./gradlew ${gradleParams} sign'

                        sh "./gradlew ${gradleParams} publishToMavenLocal"

                        sh './gradlew ${gradleParams} -Prelease publish'
                    }
                }
            }
        }
    }
}
