Files
THE-TIP-TOP/Jenkinsfile
2026-08-04 11:56:13 +00:00

120 lines
3.3 KiB
Groovy

pipeline {
agent any
options {
disableConcurrentBuilds()
timestamps()
}
environment {
CI_NETWORK = "tiptop-ci-${BUILD_NUMBER}"
CI_DATABASE = "tiptop-ci-db-${BUILD_NUMBER}"
DATABASE_URL = "postgresql://tiptop_ci:tiptop_ci_password@${CI_DATABASE}:5432/the_tip_top_ci"
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Backend - Tests') {
steps {
sh '''
docker network create "${CI_NETWORK}"
docker run -d \
--name "${CI_DATABASE}" \
--network "${CI_NETWORK}" \
-e POSTGRES_USER=tiptop_ci \
-e POSTGRES_PASSWORD=tiptop_ci_password \
-e POSTGRES_DB=the_tip_top_ci \
postgres:16-alpine
echo "Attente de PostgreSQL..."
for i in $(seq 1 30); do
if docker exec "${CI_DATABASE}" \
pg_isready -U tiptop_ci -d the_tip_top_ci; then
echo "PostgreSQL est prêt."
break
fi
if [ "$i" -eq 30 ]; then
echo "PostgreSQL ne répond pas."
exit 1
fi
sleep 2
done
docker run --rm \
--network "${CI_NETWORK}" \
--user "$(id -u):$(id -g)" \
-e HOME=/tmp \
-e DATABASE_URL="${DATABASE_URL}" \
-e JWT_SECRET=jenkins_ci_secret \
-e NODE_ENV=test \
-v "${WORKSPACE}/backend:/app" \
-w /app \
node:22-alpine \
sh -c "
npm ci &&
npx prisma generate &&
npx prisma migrate deploy &&
npm test
"
'''
}
}
stage('Frontend - Lint and Build') {
steps {
sh '''
docker run --rm \
--user "$(id -u):$(id -g)" \
-e HOME=/tmp \
-v "${WORKSPACE}/frontend:/app" \
-w /app \
node:22-alpine \
sh -c "
npm ci &&
npm run lint &&
npm run build
"
'''
}
}
stage('Docker Build') {
steps {
sh '''
docker compose \
-f docker-compose.dev.yml \
build
'''
}
}
}
post {
always {
sh '''
docker rm -f "${CI_DATABASE}" 2>/dev/null || true
docker network rm "${CI_NETWORK}" 2>/dev/null || true
'''
deleteDir()
}
success {
echo 'Pipeline CI réussi.'
}
failure {
echo 'Pipeline CI en échec. Consulte la Console Output.'
}
}
}