Jenkins/vars/pa11y.groovy

52 lines
1.7 KiB
Groovy
Raw Permalink Normal View History

2020-08-10 15:15:32 +02:00
def audit(String url, Map params = [:]) {
def reporter = params.reporter ? params.reporter : 'html'
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;
2020-08-10 15:15:32 +02:00
def pa11yImage = buildDockerImage()
def dockerArgs = """
-e PA11Y_REPORTER='${reporter}'
-e PA11Y_URL='${url}'
-e PA11Y_USERNAME='${username}'
-e PA11Y_PASSWORD='${password}'
-e PA11Y_STANDARD='${standard}'
-e PA11Y_INCLUDE_WARNINGS='${includeWarnings}'
-e PA11Y_INCLUDE_NOTICES='${includeNotices}'
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
}
2020-08-10 15:15:32 +02:00
2020-08-10 15:03:40 +02:00
def buildDockerImage() {
dir ('.pa11y') {
def resourceFiles = [
'com/cadoles/pa11y/Dockerfile',
'com/cadoles/pa11y/patty.json.tmpl',
'com/cadoles/pa11y/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("pa11y:${imageTag}", ".")
}
}