2020-08-10 15:15:32 +02:00
|
|
|
def audit(String url, Map params = [:]) {
|
|
|
|
def reporter = params.reporter ? params.reporter : 'html'
|
2022-11-21 19:19:14 +01:00
|
|
|
def username = params.username ? params.username : ''
|
|
|
|
def password = params.password ? params.password : ''
|
|
|
|
def standard = params.standard ? params.standard : 'WCAG2AA'
|
|
|
|
def includeWarnings = params.includeWarnings ? params.includeWarnings : false
|
|
|
|
def includeNotices = params.includeNotices ? params.includeNotices : false
|
|
|
|
def cookie = params.cookie ? params.cookie : ''
|
|
|
|
def ignoredRules = params.ignoredRules ? params.ignoredRules : ''
|
|
|
|
|
2020-08-10 15:15:32 +02:00
|
|
|
def pa11yImage = buildDockerImage()
|
|
|
|
|
|
|
|
def dockerArgs = """
|
|
|
|
-e PA11Y_REPORTER='${reporter}'
|
|
|
|
-e PA11Y_URL='${url}'
|
2020-08-10 16:48:05 +02:00
|
|
|
-e PA11Y_USERNAME='${username}'
|
|
|
|
-e PA11Y_PASSWORD='${password}'
|
2020-08-11 10:22:57 +02:00
|
|
|
-e PA11Y_STANDARD='${standard}'
|
2020-08-11 10:53:49 +02:00
|
|
|
-e PA11Y_INCLUDE_WARNINGS='${includeWarnings}'
|
|
|
|
-e PA11Y_INCLUDE_NOTICES='${includeNotices}'
|
2022-11-21 19:19:14 +01:00
|
|
|
-e PA11Y_COOKIE='${cookie}'
|
|
|
|
-e PA11Y_IGNORE='${ignoredRules}'
|
2020-08-10 15:15:32 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
pa11yImage.inside(dockerArgs) {
|
|
|
|
sh 'chown -R pa11y: ./'
|
|
|
|
def report = sh(
|
|
|
|
script: 'su pa11y - /usr/local/bin/run-audit',
|
|
|
|
returnStdout: true
|
|
|
|
)
|
|
|
|
|
|
|
|
return report
|
|
|
|
}
|
2020-08-10 15:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def buildDockerImage() {
|
2022-11-21 19:19:14 +01:00
|
|
|
dir('.pa11y') {
|
2020-08-10 15:03:40 +02:00
|
|
|
def resourceFiles = [
|
|
|
|
'com/cadoles/pa11y/Dockerfile',
|
|
|
|
'com/cadoles/pa11y/patty.json.tmpl',
|
|
|
|
'com/cadoles/pa11y/run-audit.sh'
|
2022-11-21 19:19:14 +01:00
|
|
|
]
|
2020-08-10 15:03:40 +02:00
|
|
|
|
|
|
|
for (res in resourceFiles) {
|
|
|
|
def fileContent = libraryResource res
|
2022-11-21 19:19:14 +01:00
|
|
|
def fileName = res.substring(res.lastIndexOf('/') + 1)
|
2020-08-10 15:03:40 +02:00
|
|
|
writeFile file:fileName, text:fileContent
|
|
|
|
}
|
2022-11-21 19:19:14 +01:00
|
|
|
|
2020-08-10 15:03:40 +02:00
|
|
|
def safeJobName = URLDecoder.decode(env.JOB_NAME).toLowerCase().replace('/', '-').replace(' ', '-')
|
|
|
|
def imageTag = "${safeJobName}-${env.BUILD_ID}"
|
2022-11-21 19:19:14 +01:00
|
|
|
return docker.build("pa11y:${imageTag}", '.')
|
2020-08-10 15:03:40 +02:00
|
|
|
}
|
2022-11-21 19:19:14 +01:00
|
|
|
}
|