Jenkins/vars/pa11y.groovy

55 lines
1.8 KiB
Groovy

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
def cookie = params.cookie ? params.cookie : ''
def ignoredRules = params.ignoredRules ? params.ignoredRules : ''
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}'
-e PA11Y_COOKIE='${cookie}'
-e PA11Y_IGNORE='${ignoredRules}'
"""
pa11yImage.inside(dockerArgs) {
sh 'chown -R pa11y: ./'
def report = sh(
script: 'su pa11y - /usr/local/bin/run-audit',
returnStdout: true
)
return report
}
}
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}", '.')
}
}