Skip to content
Snippets Groups Projects
Commit b6b620e0 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

initial commit

parents
Branches
No related tags found
No related merge requests found
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
include:
- local: /templates/validation.yml
stages:
- build
variables:
GITLAB_CI_FILES: "templates/*.yml"
# GitLab CI Stuff
## Overview
This template provides a jobs to validate your template syntax.
It uses the [GitLab CI Lint API](https://docs.gitlab.com/ee/api/lint.html).
## Template validation
The template implements a `gitlab-ci-lint` job, enabled with `GITLAB_CI_FILES` variable (GitLab CI files pattern(s) to analyse).
Example of a `.gitlab-ci.yml` file for a GitLab CI template project:
```yaml
include:
- project: 'to-be-continuous/tools/gitlab-ci'
ref: 'master'
file: '/templates/validation.yml'
stages:
- build
variables:
GITLAB_CI_FILES: "templates/*.yml"
```
logo.png 0 → 100644
logo.png

16 KiB

.lint-scripts: &lint-scripts |
set -e
function log_info() {
echo -e "[\e[1;94mINFO\e[0m] $*"
}
function log_error() {
echo -e "[\e[1;91mERROR\e[0m] $*" >&2
}
function install_ca_certs() {
certs=$1
if [[ -z "$certs" ]]
then
return
fi
# import in system
if echo "$certs" >> /etc/ssl/certs/ca-certificates.crt
then
log_info "CA certificates imported in \\e[33;1m/etc/ssl/certs/ca-certificates.crt\\e[0m"
fi
if echo "$certs" >> /etc/ssl/cert.pem
then
log_info "CA certificates imported in \\e[33;1m/etc/ssl/cert.pem\\e[0m"
fi
}
# validates an input GitLab CI YAML file
function ci_lint() {
rc=0
for file in $(eval "ls -1 $GITLAB_CI_FILES")
do
log_info "Validating: $file..."
REQUEST="{\"content\": $(jq --raw-input --slurp '.' < "${file:-/dev/stdin}")}"
RESULT=$(curl -s --header "Content-Type: application/json" --header "PRIVATE-TOKEN: $GITLAB_TOKEN" $CI_API_V4_URL/ci/lint --data "$REQUEST")
if [ "$(echo "$RESULT" | jq '.status')" == "\"valid\"" ]
then
log_info " ... valid ($RESULT)"
else
log_error " ... invalid: $RESULT"
rc=1
fi
done
exit $rc
}
gitlab-ci-lint:
image: dwdraju/alpine-curl-jq:latest
stage: build
before_script:
- *lint-scripts
- install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
script:
- ci_lint
rules:
# exclude merge requests
- if: $CI_MERGE_REQUEST_ID
when: never
# enabled if $GITLAB_TOKEN and GITLAB_CI_FILES are set
- if: '$GITLAB_TOKEN && $GITLAB_CI_FILES'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment