pipeline {
  agent any
  options {
    buildDiscarder(logRotator(numToKeepStr: "100"))
    skipDefaultCheckout(true)
  }
  triggers {
    pollSCM("*/10 * * * *")
  }
  environment {
    SONAR_SCANNER_VERSION="4.7.0.2747"
    SONAR_SCANNER_HOME="$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux"
    PATH="$SONAR_SCANNER_HOME/bin:$PATH"
    SONAR_SCANNER_OPTS="-server"
  }
  stages {
    stage('Checkout'){
      steps{
        cleanWs()
        checkout scm
     }
    }
    stage('Clean'){
      steps {
        withEnv(["PATH+RUST=$HOME/.cargo/bin"]) { // Cargo needs to be installed for the jenkins user
          sh 'cargo clean'
        }
      }
    }
    stage('Build'){
      steps {
        withSonarQubeEnv(installationName: 'SQ Bib Watcher', envOnly: true) {
          withEnv(["PATH+RUST=$HOME/.cargo/bin"]) {
            sh 'cargo build --release'
          }
        }
      }
    }
    /*
    stage('SonarQube Analysis') {
      steps {
        withSonarQubeEnv('grover.local:9000') {
          sh """
          printenv
          cargo clippy --message-format=json &> clippy-output.json
          sonar-scanner -Dsonar.projectKey=bib-watcher -Dsonar.sources=. -Dsonar.host.url=http://grover.local:9000
          """
        }
      }
    }
    */
  }
}