Zack Williams | e64341b | 2018-04-10 22:14:35 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # jflint.sh - lint for Jenkins declarative pipeline jobs |
| 4 | # |
| 5 | # curl commands from: https://jenkins.io/doc/book/pipeline/development/#linter |
| 6 | |
| 7 | set -e -u -o pipefail |
| 8 | |
| 9 | JENKINS_URL=https://jenkins-new.opencord.org/ |
| 10 | JF_LIST=() |
| 11 | |
| 12 | # if no args, and there's a Jenkinsfile in cwd, check it |
| 13 | if [ ! -n "$1" ] && [ -f "Jenkinsfile" ] ; then |
| 14 | JF_LIST+=("Jenkinsfile") |
| 15 | else |
| 16 | # iterate over all args, check if they exist, then add to list of jenkinsfiles to check |
| 17 | for arg in "$@"; do |
| 18 | if [ -f "$arg" ]; then |
| 19 | JF_LIST+=($arg) |
| 20 | else |
| 21 | echo "File does not exist: ${arg}" |
| 22 | exit 1; |
| 23 | fi |
| 24 | done |
| 25 | fi |
| 26 | |
| 27 | # JENKINS_CRUMB is needed if your Jenkins master has CRSF protection enabled as it should |
| 28 | JENKINS_CRUMB=$(curl "$JENKINS_URL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)") |
| 29 | |
| 30 | for target in "${JF_LIST[@]-}"; do |
| 31 | echo "Checking '${target}'" |
| 32 | curl -X POST -H "${JENKINS_CRUMB}" -F "jenkinsfile=<${target}" $JENKINS_URL/pipeline-model-converter/validate |
| 33 | done |
| 34 | |