blob: 94b618af2cb2cf753da6dffcc47f1b868bf064f6 [file] [log] [blame]
#!groovy
def main() {
String gitUrl = "${env.GERRIT_SCHEME}://${env.GERRIT_HOST}:${env.GERRIT_PORT}/${env.GERRIT_PROJECT}"
String gitRef = env.GERRIT_REFSPEC
stage('SCM checkout') {
echo "Checking out git repository from ${gitUrl} @ ${gitRef}"
checkout \
$class: 'GitSCM',
branches: [[
name: 'FETCH_HEAD'
]],
userRemoteConfigs: [[
url: gitUrl,
refspec: gitRef,
credentialsId: env.GIT_CREDENTIALS_ID
]],
extensions: [[
$class: 'WipeWorkspace'
]]
}
stage('Yamllint') {
sh '''#!/bin/bash -ex
YAMLLINT=$(which yamllint)
[ -f '.yamllint' ] && YAMLLINT="${YAMLLINT} -c .yamllint"
git diff HEAD^ --name-only --diff-filter=AM \
| grep -E '\\.ya?ml$' \
| xargs --no-run-if-empty ${YAMLLINT}
'''
}
}
String podTpl = """
apiVersion: "v1"
kind: "Pod"
spec:
securityContext:
runAsUser: 1000
containers:
- name: "yamllint"
image: "${env.DOCKER_IMAGE}"
command:
- "cat"
securityContext:
privileged: false
tty: true
"""
if (env.K8S_CLUSTER == 'unset') {
node(env.NODE_LABEL) {
docker.image(env.DOCKER_IMAGE).inside('--entrypoint=""') {
main()
}
}
} else {
podTemplate(
cloud: env.K8S_CLUSTER,
yaml: podTpl,
showRawYaml: false
) {
node(POD_LABEL) {
container('yamllint') {
main()
}
}
}
}