blob: 8ece6b793839639d546fd2bd280a0f1eb167f3a5 [file] [log] [blame]
Zack Williamse64341b2018-04-10 22:14:35 -07001#!/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
7set -e -u -o pipefail
8
9JENKINS_URL=https://jenkins-new.opencord.org/
10JF_LIST=()
11
12# if no args, and there's a Jenkinsfile in cwd, check it
13if [ ! -n "$1" ] && [ -f "Jenkinsfile" ] ; then
14 JF_LIST+=("Jenkinsfile")
15else
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
25fi
26
27# JENKINS_CRUMB is needed if your Jenkins master has CRSF protection enabled as it should
28JENKINS_CRUMB=$(curl "$JENKINS_URL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)")
29
30for 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
33done
34