ci(lighthouse): add jenkins lighthouse automated audit
Some checks failed
Portfolio/pipeline/head There was a failure building this commit
Some checks failed
Portfolio/pipeline/head There was a failure building this commit
This commit is contained in:
27
Jenkinsfile
vendored
27
Jenkinsfile
vendored
@@ -2,6 +2,7 @@ pipeline {
|
||||
agent any
|
||||
environment {
|
||||
DOCKER_HOST = "unix:///var/run/docker.sock"
|
||||
APP_VERSION = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
|
||||
}
|
||||
stages {
|
||||
stage('Build') {
|
||||
@@ -9,12 +10,25 @@ pipeline {
|
||||
// Get Caddy version
|
||||
sh "cp .env.dist .env"
|
||||
// Push portfolio version
|
||||
sh "echo '\nPORTFOLIO_VERSION=${env.BRANCH_NAME}-${env.BUILD_NUMBER}' >> .env"
|
||||
sh "echo '\nPORTFOLIO_VERSION=${env.APP_VERSION}' >> .env"
|
||||
|
||||
echo "Building new portfolio version..."
|
||||
sh "docker compose build"
|
||||
}
|
||||
}
|
||||
stage('Lighthouse Audit') {
|
||||
steps {
|
||||
// Temporary container to get data in /dist folder
|
||||
// Reuse of just build portfolio image
|
||||
sh "mkdir -p ./dist-audit ./.lighthouseci"
|
||||
sh "docker create --name audit-tmp portfolio:${env.APP_VERSION}"
|
||||
sh "docker cp audit-tmp:/usr/share/caddy/. ./dist-audit"
|
||||
sh "docker rm audit-tmp"
|
||||
|
||||
// Launch special service in docker compose
|
||||
sh "docker compose --profile audit run --rm lighthouse-audit"
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
// Deploy only master branch
|
||||
when {
|
||||
@@ -35,8 +49,17 @@ pipeline {
|
||||
}
|
||||
post {
|
||||
always {
|
||||
echo "Clean unused image..."
|
||||
echo "Publish Lighthouse audit..."
|
||||
publishHTML([
|
||||
allowMissing: true,
|
||||
alwaysLinkToLastBuild: true,
|
||||
reportDir: '.lighthouseci',
|
||||
reportFiles: 'index.html',
|
||||
reportName: 'Lighthouse Report'
|
||||
])
|
||||
echo "Clean unused image and files..."
|
||||
sh "docker image prune -f"
|
||||
sh "rm -rf ./dist-audit"
|
||||
}
|
||||
success { echo "Success !" }
|
||||
failure { echo "Failed." }
|
||||
|
||||
Reference in New Issue
Block a user