pipeline 
{ 
    agent any

    environment
    {
        SUDO_PASSWORD = credentials('sudo-password')
    }

    stages 
    { 
        stage ( 'checkout' )
        { 
            steps 
            { 
                sh 'echo "Debut du pipeline"'
                checkout scm 
            } 
        }
        stage ( 'Deploiement' ) 
        { 
            when { branch 'main' }
            steps {
                sh '''
                cd /var/www/sirh
                echo $SUDO_PASSWORD | sudo -S chown -R jenkins:jenkins /var/www/sirh
                git pull origin main
                python3 -m venv venv 
                . venv/bin/activate
                pip install -r requirements.txt
                python manage.py makemigrations
                python manage.py migrate
                echo "Deploiement reussi"
                '''
            }
        } 
    }
}