pipeline {
  agent any
  options {
    timestamps()
    disableConcurrentBuilds()
  }
  stages {
    stage('Build & Test') {
      steps {
        sh 'chmod +x gradlew'
        sh './gradlew clean build --no-daemon'
      }
    }
    stage('Deploy') {
      steps {
        sh '''
          set -e
          JAR=$(ls build/libs/h-lab-*.jar | grep -v plain | head -1)
          echo "Deploying: $JAR"
          docker cp "$JAR" springboot-app:/app/app.jar
          docker restart springboot-app
        '''
      }
    }
  }
}