blob: e7b76f01c4d5e0bb8316d8d48ebf3a9b8ace8eaa [file] [log] [blame]
Zack Williamse64341b2018-04-10 22:14:35 -07001#!/usr/bin/env bash
2
Zack Williams32293ee2018-05-18 09:15:13 -07003# Copyright 2017-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Zack Williamse64341b2018-04-10 22:14:35 -070017# jflint.sh - lint for Jenkins declarative pipeline jobs
18#
19# curl commands from: https://jenkins.io/doc/book/pipeline/development/#linter
20
21set -e -u -o pipefail
22
23JENKINS_URL=https://jenkins-new.opencord.org/
24JF_LIST=()
25
26# if no args, and there's a Jenkinsfile in cwd, check it
27if [ ! -n "$1" ] && [ -f "Jenkinsfile" ] ; then
28 JF_LIST+=("Jenkinsfile")
29else
30# iterate over all args, check if they exist, then add to list of jenkinsfiles to check
31 for arg in "$@"; do
32 if [ -f "$arg" ]; then
33 JF_LIST+=($arg)
34 else
35 echo "File does not exist: ${arg}"
36 exit 1;
37 fi
38 done
39fi
40
41# JENKINS_CRUMB is needed if your Jenkins master has CRSF protection enabled as it should
42JENKINS_CRUMB=$(curl "$JENKINS_URL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)")
43
44for target in "${JF_LIST[@]-}"; do
45 echo "Checking '${target}'"
46 curl -X POST -H "${JENKINS_CRUMB}" -F "jenkinsfile=<${target}" $JENKINS_URL/pipeline-model-converter/validate
47done
48