Files
reverse-proxy/Jenkinsfile
Lucas 047fde1cf5
All checks were successful
jenkins-ci Build successful
New try
2026-01-08 20:19:05 +01:00

72 lines
2.4 KiB
Groovy
Executable File

pipeline {
agent any
environment {
GITEA_REPO_PATH = "server/reverse-proxy"
GITEA_API_URL = "https://gitea.lucasroyer.fr/api/v1"
}
stages {
stage('Check git...') {
steps {
checkout scm
}
}
stage('Build') {
steps {
echo "Build Caddy with cache plugin..."
sh "docker compose build --pull"
}
}
stage('Deploy') {
steps {
echo "Deploy new reverse proxy..."
sh "docker compose up -d"
}
}
stage('Check module...') {
steps {
script {
// Ask caddy to list modules
def modules = sh(script: "docker exec caddy-reverse-proxy caddy list-modules", returnStdout: true)
if (modules.contains('http.handlers.cache')) {
echo "Cache module activated"
} else {
error "Error : can't find cache module"
}
}
}
}
}
post {
always {
script {
// 1. Get current commit SHA
def commitSha = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
// 2. Determine build status for Gitea
def buildState = currentBuild.currentResult == 'SUCCESS' ? 'success' : 'failure'
def buildDesc = currentBuild.currentResult == 'SUCCESS' ? 'Build successful' : 'Build failed'
// 3. Send status to Gitea API using our new 'gitea-token'
withCredentials([string(credentialsId: 'gitea-token', variable: 'GITEA_TOKEN')]) {
sh """
curl -f -X POST "${GITEA_API_URL}/repos/${GITEA_REPO_PATH}/statuses/${commitSha}" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"state": "${buildState}", "target_url": "${env.BUILD_URL}", "description": "${buildDesc}", "context": "jenkins-ci"}'
"""
}
}
echo "Clean unused image..."
sh "docker image prune -f"
}
success {
echo "Success !"
}
failure {
echo "Failed."
}
}
}