Skip to content

Commit a9f7040

Browse files
committed
Add Jenkins pipeline linter
Change-Id: I3ea496933837fd03423286a3c7c27ebd8672ae44
1 parent c641d2a commit a9f7040

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jenkins.war
1313
nosetests.xml
1414
coverage*/
1515
.idea/
16-
bin/
1716
include/
1817
lib/
1918
*.egg

bin/pipelint

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
INPUT=/dev/stdin
5+
if [ -t 0 ]; then
6+
if [ "$#" -ne 1 ]; then
7+
echo "ERROR: Illegal number of parameters."
8+
echo "INFO: Use 'pipefail Jenkinsfile' or 'cat Jenkinsfile | pipefail'"
9+
exit 1
10+
fi
11+
INPUT=$1
12+
fi
13+
# put credentials inside ~/.netrc
14+
# define JENKINS_URL in your user profile
15+
JENKINS_URL=${JENKINS_URL:-http://localhost:8080}
16+
17+
# failure to get crumb is ignored as this may be diabled on the server side
18+
CRUMB="-H `curl -nfs "$JENKINS_URL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,%22:%22,//crumb)"`" || CRUMB=''
19+
20+
# The tee+grep trick assures that the exit code is 0 only if the server replied with "successfully validated"
21+
curl -nfs -X POST $CRUMB -F "jenkinsfile=<-" $JENKINS_URL/pipeline-model-converter/validate <$INPUT \
22+
| tee >(cat 1>&2) | grep 'successfully validated' >/dev/null

0 commit comments

Comments
 (0)