2020-06-24 07:51:04 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-07-12 14:19:25 +00:00
|
|
|
###
|
|
|
|
### checkci — checks a Jenkinsfile syntax against a real Jenkins instance
|
|
|
|
###
|
|
|
|
### Note: this script gets:
|
|
|
|
### the (jenkins) username from git config
|
|
|
|
### the (jenkins) password/secret from Environment variable $JENKINS_SECRET
|
|
|
|
### the (jenkins) URL from Environment variable $JENKINS_URL
|
|
|
|
###
|
|
|
|
### Usage:
|
|
|
|
### checkci.sh [jenkinsfile]
|
|
|
|
###
|
|
|
|
### Options:
|
|
|
|
### [input] path to Jenkinsfile (optional).
|
|
|
|
### -h Show this message.
|
|
|
|
|
|
|
|
help() {
|
|
|
|
gsed -rn 's/^### ?//;T;p' "$0"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $# == 0 ]] || [[ "$1" == "-h" ]]; then
|
|
|
|
help
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-06-24 07:51:04 +00:00
|
|
|
function _checkci() {
|
2020-07-11 10:25:30 +00:00
|
|
|
local username
|
2020-07-18 14:55:52 +00:00
|
|
|
username="$(git config --global -l G "user.email" | cut -d'@' -f1 | cut -d'=' -f2)"
|
2020-07-11 10:25:30 +00:00
|
|
|
local jenkinsfile="${1:-Jenkinsfile}"
|
|
|
|
curl --user "$username:$JENKINS_SECRET" -X POST -F "jenkinsfile=<$jenkinsfile" "$JENKINS_URL/pipeline-model-converter/validate"
|
2020-06-24 07:51:04 +00:00
|
|
|
}
|
|
|
|
_checkci "$*"
|
|
|
|
exit 0
|