pipeline { agent any stages { stage('Build') { steps { echo 'Compilation du code...' // Add your build commands here } } stage('Test') { steps { echo 'Exécution des tests...' // Add your test commands here } } stage('Deploy') { steps { echo 'Déploiement sur Portainer...' // Obtain an authentication token from Portainer withCredentials([usernamePassword(credentialsId: 'portainer-credentials', usernameVariable: 'PORTAINER_USERNAME', passwordVariable: 'PORTAINER_PASSWORD')]) { script { def response = httpRequest httpMode: 'POST', contentType: 'APPLICATION_JSON', url: "http://portainer.canguidev.fr/api/auth", requestBody: "{\"Username\":\"${PORTAINER_USERNAME}\",\"Password\":\"${PORTAINER_PASSWORD}\"}" def json = readJSON text: response.content env.PORTAINER_TOKEN = json.jwt } } // Deploy the stack on Portainer using the obtained token httpRequest httpMode: 'PUT', customHeaders: [[name: 'Authorization', value: "Bearer ${env.PORTAINER_TOKEN}"]], url: "http://portainer.canguidev.fr/api/stacks/canguidev/deploy", contentType: 'APPLICATION_JSON', requestBody: '{"Prune": true}' echo 'Déploiement terminé.' } } } }