2019-12-24 12:54:32 +01:00
|
|
|
// 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 !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-26 12:10:23 +01:00
|
|
|
stage("Run Lighthouse and pa11y audits") {
|
2019-12-24 12:54:32 +01:00
|
|
|
steps {
|
|
|
|
script {
|
|
|
|
def lighthouseImage = buildDockerImage()
|
|
|
|
def dockerArgs = """
|
|
|
|
-e LIGHTHOUSE_URL='${params.url}'
|
|
|
|
"""
|
|
|
|
timeout(params.auditTimeout.toInteger()) {
|
|
|
|
lighthouseImage.inside(dockerArgs) {
|
2019-12-26 12:10:23 +01:00
|
|
|
sh 'chown -R lighthouse: ./'
|
|
|
|
sh 'su lighthouse - /usr/local/bin/run-audit'
|
2019-12-24 12:54:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-26 12:10:23 +01:00
|
|
|
|
2019-12-24 12:54:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
post {
|
|
|
|
always {
|
|
|
|
publishHTML target: [
|
|
|
|
allowMissing: true,
|
|
|
|
alwaysLinkToLastBuild: false,
|
|
|
|
keepAll: true,
|
|
|
|
reportDir: 'reports',
|
2019-12-26 12:10:23 +01:00
|
|
|
reportFiles: '*.report.html',
|
|
|
|
reportName: "Rapports d'audit"
|
2019-12-24 12:54:32 +01:00
|
|
|
]
|
|
|
|
cleanWs()
|
|
|
|
}
|
|
|
|
success {
|
|
|
|
wrap([$class: 'BuildUser']) {
|
|
|
|
rocketSend (
|
|
|
|
avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png',
|
|
|
|
message: """
|
2019-12-26 12:10:23 +01:00
|
|
|
Les audits pour `${params.url}` sont terminés:
|
2019-12-24 12:54:32 +01:00
|
|
|
|
2019-12-26 12:10:23 +01:00
|
|
|
- [Voir le rapport Lighthouse (bonnes pratiques)](${env.BUILD_URL}Rapports_20d_27audit/lighthouse.report.html)
|
|
|
|
- [Voir le rapport pa11y (accessibilité)](${env.BUILD_URL}Rapports_20d_27audit/pa11y.report.html)
|
2019-12-24 12:54:32 +01:00
|
|
|
|
2019-12-26 12:10:23 +01:00
|
|
|
[Lancer un nouvel audit](${env.BUILD_URL}../build)
|
|
|
|
|
2019-12-24 12:54:32 +01:00
|
|
|
@${env.BUILD_USER_ID ? env.BUILD_USER_ID : 'here'}
|
|
|
|
""".stripIndent(),
|
|
|
|
rawMessage: true
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
failure {
|
2019-12-26 12:10:23 +01:00
|
|
|
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
|
|
|
|
)
|
|
|
|
}
|
2019-12-24 12:54:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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}", ".")
|
|
|
|
}
|
|
|
|
}
|