canguidev/Jenkinsfile

59 lines
2.3 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 {
2024-10-06 17:01:28 +00:00
// Create a JSON object for the authentication request
def authRequestBody = groovy.json.JsonOutput.toJson([
Username: PORTAINER_USERNAME,
Password: PORTAINER_PASSWORD
])
// Send the authentication request without logging sensitive data
def response = httpRequest(
httpMode: 'POST',
2024-10-06 16:47:29 +00:00
contentType: 'APPLICATION_JSON',
url: "http://portainer.canguidev.fr/api/auth",
2024-10-06 17:01:28 +00:00
requestBody: authRequestBody,
consoleLogResponseBody: false // Prevent logging the response body
)
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 17:01:28 +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',
2024-10-06 17:01:28 +00:00
requestBody: '{"Prune": true}',
consoleLogResponseBody: false // Prevent logging the response body
)
2024-10-06 16:47:29 +00:00
echo 'Déploiement terminé.'
}
}
}
}