Merge pull request 'Update jenkinsfile.ci' (#30) from feature/main-UpdateJenkinsFileCi into main

Reviewed-on: #30
This commit was merged in pull request #30.
This commit is contained in:
2026-02-06 21:39:23 +01:00
3 changed files with 69 additions and 33 deletions

View File

@@ -36,32 +36,6 @@ pipeline {
stages {
/* =========================
TESTS
========================= */
stage('Backend: test (main)') {
agent {
docker {
image 'python:3.11-slim'
args '-u root'
}
}
steps {
dir('backend') {
sh '''
set -e
python -m venv .venv
. .venv/bin/activate
pip install --upgrade pip
pip install -r requirements-dev.txt
pytest
'''
}
}
}
/* =========================
DOCKER BUILD
========================= */

View File

@@ -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
'''
}
}
@@ -84,6 +84,7 @@ pipeline {
mkdir -p "$NPM_CONFIG_CACHE"
npm install --no-progress --no-audit --prefer-offline
npm run check
mkdir -p test-results
npm test
npm run build
'''
@@ -93,13 +94,74 @@ pipeline {
}
post {
always {
script {
node {
cleanWs()
post {
always {
script {
node {
junit testResults: 'backend/pytest.xml', allowEmptyResults: true
junit testResults: 'frontend/test-results/junit.xml', allowEmptyResults: true
if (env.CHANGE_ID) {
def giteaBase = 'https://openbokeron.org'
def owner = 'OpenBokeron'
def repo = 'TallerCiCd'
def pr = env.CHANGE_ID
def result = currentBuild.currentResult
def msg = ""
if (result == "SUCCESS") {
msg = """
✅ Todo en orden, camarada.
- URL: ${env.BUILD_URL}
""".stripIndent().trim()
}
else if (result == "FAILURE") {
msg = """
❌ Alto ahí. ¿Qué clase de crímenes de guerra has cometido en esta PR?
- URL: ${env.BUILD_URL}
""".stripIndent().trim()
}
else {
msg = """
⚠️ Dudoso…
- URL: ${env.BUILD_URL}
""".stripIndent().trim()
}
def commentsUrl = "${giteaBase}/gitea/api/v1/repos/${owner}/${repo}/issues/${pr}/comments"
withCredentials([usernamePassword(credentialsId: 'jenkins-bot-api',
usernameVariable: 'GITEA_USER',
passwordVariable: 'GITEA_TOKEN')]) {
def body = msg.replace('\\', '\\\\').replace('"','\\"').replace('\n','\\n')
// Avoid interpolation of secret variables (https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#string-interpolation)
withEnv(["GITEA_COMMENTS_URL=${commentsUrl}", "GITEA_BODY=${body}"]) {
sh(label: 'Comentar en PR (Gitea)', script: '''
curl -sS -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
--data-binary @- \
"$GITEA_COMMENTS_URL" <<JSON
{"body":"$GITEA_BODY"}
JSON
''')
}
}
} else {
echo "No es build de PR (CHANGE_ID vacío); no comento."
}
cleanWs()
}
}
}
}
}

View File

@@ -8,7 +8,7 @@
"build": "vite build",
"preview": "vite preview",
"check": "svelte-check",
"test": "vitest"
"test": "vitest run --reporter=default --reporter=junit --outputFile=./test-results/junit.xml"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.0.1",