pipeline {
    agent any

    tools {
        jdk 'jenkins-jdk'
        maven 'jenkins-maven'
    }

    stages {
        stage('Checkout') {
            steps {
                git url: 'https://gitlab.com/christianakpona/infocad.git', branch: 'main'
            }
        }

        stage('Build') {
            steps {
                sh 'mvn clean package'
            }
        }

        stage('Lint') {
            steps {
                // Change directory to 'ansible/' before running ansible-lint
                dir('ansible') {
                    sh '/usr/local/bin/ansible-lint playbook_jenkins.yml'
                }
            }
        }

        stage('Deploy') {
            steps {
                // Change directory to 'ansible/' before running ansible-playbook
                dir('ansible') {
                    sh '/usr/local/bin/ansible-playbook playbook_jenkins.yml'
                }
            }
        }
    }
}