// Build and test project generations with documentation
properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '5', artifactNumToKeepStr: '5', daysToKeepStr: '5', numToKeepStr: '5'))])
node {
    stage("Build") {
        deleteDir()
        checkout scm
        withCredentials([usernamePassword(credentialsId: '201ea374-bda3-4a38-a18a-ccc9c39fb3ff', passwordVariable: 'ORG_GRADLE_PROJECT_nexusPassword', usernameVariable: 'ORG_GRADLE_PROJECT_nexusUsername')]) {
            sh "chmod +x gradlew"
            sh "./gradlew clean build asciidoctor -PnexusUrl=https://nexus.ingenieurbuero-peetz.de"
        }
        withCredentials([usernamePassword(credentialsId: 'IBTPJenkinsBot', passwordVariable: 'TOKEN', usernameVariable: 'CHAT')]) {
            sh script:"curl -s -X POST https://api.telegram.org/bot$TOKEN/sendMessage -d chat_id=$CHAT -d text='Job ${env.BUILD_TAG} ended successfully, ${env.BUILD_URL}' > /dev/null", returnStatus: true
        }
    }
    stage("Publish Build Results") {
        junit allowEmptyResults: true, testResults: '**/build/test-results/**/*.xml'
        openTasks canComputeNew: false, defaultEncoding: 'UTF-8', excludePattern: '', healthy: '', high: '', ignoreCase: true, low: '', normal: '', pattern: '*.gradle,**/*.java,**/*.adoc', unHealthy: ''
        archiveArtifacts allowEmptyArchive: true, artifacts: "build/asciidoc/pdf/generations.pdf"
    }
    stage("Publish HTML") {
        publishHTML(target: [
            allowMissing: true,
            alwaysLinkToLastBuild: true,
            keepAll: false, reportDir: 'build/asciidoc/html5',
            reportFiles: "generations.html",
            reportName: "generations"
        ])
    }
}
