113 lines
3.6 KiB
Groovy
113 lines
3.6 KiB
Groovy
// 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 !")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage("Run Lighthouse audit") {
|
|
steps {
|
|
script {
|
|
def lighthouseImage = buildDockerImage()
|
|
def dockerArgs = """
|
|
-e LIGHTHOUSE_URL='${params.url}'
|
|
"""
|
|
timeout(params.auditTimeout.toInteger()) {
|
|
lighthouseImage.inside(dockerArgs) {
|
|
sh 'run-audit'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
always {
|
|
publishHTML target: [
|
|
allowMissing: true,
|
|
alwaysLinkToLastBuild: false,
|
|
keepAll: true,
|
|
reportDir: 'reports',
|
|
reportFiles: 'lighthouse.report.html',
|
|
reportName: "Rapport Lighthouse"
|
|
]
|
|
cleanWs()
|
|
}
|
|
success {
|
|
wrap([$class: 'BuildUser']) {
|
|
rocketSend (
|
|
avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png',
|
|
message: """
|
|
L'audit Lighthouse pour `${params.url}` est terminé.
|
|
|
|
[Voir le rapport](${env.BUILD_URL}Rapport_20Lighthouse/)
|
|
|
|
@${env.BUILD_USER_ID ? env.BUILD_USER_ID : 'here'}
|
|
""".stripIndent(),
|
|
rawMessage: true
|
|
)
|
|
}
|
|
}
|
|
failure {
|
|
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}", ".")
|
|
}
|
|
} |