From f431f1c5dc5935150627a1a92984f820af749829 Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 6 Feb 2026 20:27:14 +0100 Subject: [PATCH] Actualizar Jenkinsfile.ci --- Jenkinsfile.ci | 97 ++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 63 deletions(-) diff --git a/Jenkinsfile.ci b/Jenkinsfile.ci index 7e75d8f..204f6da 100644 --- a/Jenkinsfile.ci +++ b/Jenkinsfile.ci @@ -57,7 +57,7 @@ pipeline { pip install --upgrade pip pip install -r requirements-dev.txt ruff check app tests - pytest -o cache_dir="$WORKSPACE/.cache/pytest" + pytest -o cache_dir="$WORKSPACE/.cache/pytest" --junitxml=pytest.xml ''' } } @@ -93,79 +93,50 @@ pipeline { } - post { - always { - script { - node { - junit testResults: 'backend/pytest.xml', allowEmptyResults: true +post { + always { + script { + node { + junit testResults: 'backend/pytest.xml', allowEmptyResults: true - try { - if (env.CHANGE_ID) { - def owner = null - def repo = null - def giteaBase = null + if (env.CHANGE_ID) { + def giteaBase = 'https://openbokeron.org' + def owner = 'OpenBokeron' + def repo = 'TallerCiCd' + def pr = env.CHANGE_ID - if (env.CHANGE_URL) { - def u = new URL(env.CHANGE_URL) - giteaBase = "${u.protocol}://${u.host}" - def path = u.path // /gitea/OpenBokeron/TallerCiCd/pulls/29 - def m = (path =~ /\/gitea\/([^\/]+)\/([^\/]+)\/pulls\/\d+/) - if (m) { - owner = m[0][1] - repo = m[0][2] - } - } + def result = currentBuild.currentResult + def emoji = (result == 'SUCCESS') ? '✅' : (result == 'UNSTABLE') ? '⚠️' : '❌' - if ((!owner || !repo) && env.GIT_URL) { - def m = (env.GIT_URL =~ /[:\/]([^\/:]+)\/([^\/]+?)(?:\.git)?$/) - if (m) { - owner = m[0][1] - repo = m[0][2] - } + def msg = "${emoji} Jenkins: **${result}**\\n\\n" + + "- Job: `${env.JOB_NAME}`\\n" + + "- Build: #${env.BUILD_NUMBER}\\n" + + "- Commit: `${env.GIT_COMMIT?.take(7) ?: env.COMMIT_SHORT}`\\n" + + "- URL: ${env.BUILD_URL}" - if (!giteaBase) giteaBase = 'https://openbokeron.org' // AJUSTA si hace falta - } + def commentsUrl = "${giteaBase}/gitea/api/v1/repos/${owner}/${repo}/issues/${pr}/comments" - if (owner && repo && giteaBase) { - def pr = env.CHANGE_ID - def result = currentBuild.currentResult - def emoji = (result == 'SUCCESS') ? '✅' : (result == 'UNSTABLE') ? '⚠️' : '❌' - - def msg = "${emoji} Jenkins: **${result}**\\n\\n" + - "- Job: `${env.JOB_NAME}`\\n" + - "- Build: #${env.BUILD_NUMBER}\\n" + - "- Commit: `${env.GIT_COMMIT?.take(7) ?: env.COMMIT_SHORT}`\\n" + - "- URL: ${env.BUILD_URL}" - - def url = "${giteaBase}/gitea/api/v1/repos/${owner}/${repo}/issues/${pr}/comments" - - withCredentials([string(credentialsId: 'gitea-jenkins-bot-token', variable: 'GITEA_TOKEN')]) { - sh """ - set -e - curl -sS -X POST \ - -H "Authorization: token ${GITEA_TOKEN}" \ - -H "Content-Type: application/json" \ - --data @- \ - '${url}' <<'JSON' + withCredentials([string(credentialsId: 'gitea-jenkins-bot-token', variable: 'GITEA_TOKEN')]) { + sh """ + set -e + curl -sS -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + --data @- \ + '${commentsUrl}' <<'JSON' {"body":"${msg.replace('\\', '\\\\').replace('"','\\"')}"} JSON - """ - } - echo "Comentado en PR #${pr} (${owner}/${repo})." - } else { - echo "No pude deducir owner/repo/baseURL; no comento en la PR." - } - } else { - echo "No es build de PR (CHANGE_ID vacío); no comento." - } - } catch (err) { - echo "Fallo al comentar en PR: ${err}" + """ } - - cleanWs() + } else { + echo "No es build de PR (CHANGE_ID vacío); no comento." } + + cleanWs() } } } +} + }