2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2020 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> pipeline-linter.sh"
15 # shellcheck disable=SC2153
16 JENKINS_CRUMB=$(curl --silent "$JENKINS_URL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)")
17 JENKINS_VAL="$JENKINS_URL/pipeline-model-converter/validate"
18 mapfile -t JENKINS_FILE_LIST < <(grep -lr "^pipeline\s*{" vars src Jenkinsfile*)
21 for JENKINS_FILE in "${JENKINS_FILE_LIST[@]}"; do
22 ret=$(curl --silent -X POST -H "$JENKINS_CRUMB" -F "jenkinsfile=<$JENKINS_FILE" "$JENKINS_VAL")
23 if [[ $ret == *"Errors"* ]];then
24 echo "ERROR: Linting error for $JENKINS_FILE"
26 # Check for the line "agent any". This includes master as an agent.
27 elif grep "^\s*agent any" "$JENKINS_FILE"; then
28 echo "ERROR: $JENKINS_FILE is set to use any agent. Please specify a label instead."
30 # If "any" is not used, check for master as a specified label or node.
31 elif grep -Pz "agent\s*\{\s*(label|node)\s+['\"]*master" "$JENKINS_FILE"; then
32 echo "ERROR: $JENKINS_FILE is set to use master as an agent. Please specify a different label."
35 echo "$JENKINS_FILE successfully validated"
39 # Set non-zero exit if linter reports any errors