An easily missed feature in Jenkins is the bundled linter for Jenkinsfiles.
While there are many examples about how to use it with cURL, I could not find any using HTTPie, which I find much more convenient in general than cURL. So, after some fumbling due to the little documented expectations of the validator, here is the solution showing how to validate a Jenkinsfile from the CLI:
Let's see what these arguments mean:
--form
specifies use of theapplication/x-www-form-urlencoded
MIME type, as expected by the validator-a $USER:$PASS
provides basic authentication credentials.- If you do not want to include the password, just use
$USER:
and HTTPie will request the password on the CLI. - This assumes these two variables contain your Jenkins username and password
- If you do not want to include the password, just use
-pb
asks HTTPie to only print the response body$JENKINS_URL
is the absolute URL to the Jenkins root$JENKINSFILE
is the path to the Jenkinsfile to validate. May be relative or absolute
http
the command itself- The options, like
-a
and--form
- The method, in this case
POST
. HTTPie usesGET
by default - The target URL
- The so-called "fields", which translate to the request body. In this case, the
jenkinsfile=@$JENKINSFILE
requests HTTPie to load the contents of the file designated by$JENKINSFILE
and load that content as the value of thejenkinsfile
HTML form field
Hopefully, you will receive a result looking like this:
Jenkinsfile successfully validated.
More details in the HTTPie forms documentation.