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:
--formspecifies use of theapplication/x-www-form-urlencodedMIME type, as expected by the validator-a $USER:$PASSprovides 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
-pbasks HTTPie to only print the response body$JENKINS_URLis the absolute URL to the Jenkins root$JENKINSFILEis the path to the Jenkinsfile to validate. May be relative or absolute
httpthe command itself- The options, like
-aand--form - The method, in this case
POST. HTTPie usesGETby default - The target URL
- The so-called "fields", which translate to the request body. In this case, the
jenkinsfile=@$JENKINSFILErequests HTTPie to load the contents of the file designated by$JENKINSFILEand load that content as the value of thejenkinsfileHTML form field
Hopefully, you will receive a result looking like this:
Jenkinsfile successfully validated.
More details in the HTTPie forms documentation.