Files
gitea/Jenkinsfile
Lucas 80aa57780a
All checks were successful
jenkins-ci Build successful
fix(jenkinsfile): delay check to gitea
2026-01-23 15:52:37 +00:00

74 lines
2.8 KiB
Groovy
Executable File

pipeline {
agent any
environment {
GITEA_REPO_PATH = "lucas/gitea"
GITEA_API_URL = "https://gitea.lucasroyer.fr/api/v1"
}
stages {
stage('Check git...') {
steps {
checkout scm
}
}
stage('Deploy') {
steps {
withCredentials([
file(credentialsId: 'gitea-app-env', variable: 'APP_ENV_PATH'),
file(credentialsId: 'gitea-db-env', variable: 'DB_ENV_PATH')
]) {
echo "Deploy new gitea..."
sh """
cp "\$APP_ENV_PATH" app.env
cp "\$DB_ENV_PATH" db.env
docker compose up -d --remove-orphans
rm -f app.env db.env
"""
}
}
}
}
post {
always {
script {
echo "Waiting for Gitea to be online..."
// Try to reac gitea API for 12 tries of 10s (2 minutes)
timeout(time: 2, unit: 'MINUTES') {
waitUntil {
def status = sh(
script: "curl -s -o /dev/null -w '%{http_code}' ${GITEA_API_URL}/version || true",
returnStdout: true
).trim()
return (status == '200')
}
}
echo "Send Gitea check..."
// Get and store SHA
def commitSha = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
// Convert from Jenkins to Gitea API
def buildState = (currentBuild.currentResult == 'SUCCESS') ? 'success' : 'failure'
def buildDesc = (currentBuild.currentResult == 'SUCCESS') ? 'Build successful' : 'Build failed'
// Send it to Gitea API with secret 'gitea-token'
withCredentials([string(credentialsId: 'gitea-token', variable: 'GITEA_TOKEN')]) {
// Use \$TOKEN to avoid jenkins to print token in logs
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." }
}
}