canguidev/Jenkinsfile

46 lines
1.7 KiB
Plaintext
Raw Normal View History

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