Jenkins/vars/lighthouse.groovy

119 lines
3.9 KiB
Groovy
Raw Permalink Normal View History

// Pipeline d'exécution d'un audit Lighthouse
def call() {
pipeline {
agent {
label 'docker'
}
parameters {
string(
name: 'url',
description: 'URL cible pour l\'audit'
)
string(
name: 'auditTimeout',
description: "Délai maximum pour la réalisation de l'audit (en minutes)",
defaultValue: '60'
)
}
stages {
stage("Check parameters") {
steps {
script {
if (!params.url?.trim()) {
error("L'URL cible n'est pas définie !")
}
}
}
}
2020-08-11 14:22:03 +02:00
stage("Run Lighthouse audit") {
steps {
script {
def lighthouseImage = buildDockerImage()
def dockerArgs = """
-e LIGHTHOUSE_URL='${params.url}'
"""
timeout(params.auditTimeout.toInteger()) {
lighthouseImage.inside(dockerArgs) {
sh 'chown -R lighthouse: ./'
sh 'su lighthouse - /usr/local/bin/run-audit'
}
}
}
}
}
}
post {
always {
publishHTML target: [
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'reports',
reportFiles: '*.report.html',
reportName: "Rapports d'audit"
]
cleanWs()
}
success {
wrap([$class: 'BuildUser']) {
rocketSend (
avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png',
message: """
2020-08-11 14:22:03 +02:00
L'audit Lighthouse pour `${params.url}` est terminé:
2020-08-11 14:22:03 +02:00
- [Voir le rapport](${env.BUILD_URL}Rapports_20d_27audit/lighthouse.report.html)
[Lancer un nouvel audit](${env.BUILD_URL}../build)
@${env.BUILD_USER_ID ? env.BUILD_USER_ID : 'here'}
""".stripIndent(),
rawMessage: true
)
}
}
failure {
wrap([$class: 'BuildUser']) {
rocketSend (
avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png',
message: """
L'audit Lighthouse pour `${params.url}` a échoué:
[Voir le job](${env.RUN_DISPLAY_URL})
@${env.BUILD_USER_ID ? env.BUILD_USER_ID : 'here'}
""".stripIndent(),
rawMessage: true
)
}
}
}
}
}
def buildDockerImage() {
dir ('.lighthouse') {
def resourceFiles = [
'com/cadoles/lighthouse/Dockerfile',
'com/cadoles/lighthouse/config.js.tmpl',
'com/cadoles/lighthouse/run-audit.sh'
];
for (res in resourceFiles) {
def fileContent = libraryResource res
def fileName = res.substring(res.lastIndexOf("/")+1)
writeFile file:fileName, text:fileContent
}
def safeJobName = URLDecoder.decode(env.JOB_NAME).toLowerCase().replace('/', '-').replace(' ', '-')
def imageTag = "${safeJobName}-${env.BUILD_ID}"
return docker.build("lighthouse:${imageTag}", ".")
}
}