Validation of Jenkinsfile via API
Believe it or not, Jenkins has an API to validate jenkinsfiles: See an interesting article about it.
curl --user username:password -X POST -F "jenkinsfile=<Jenkinsfile" http://jenkins-url:8080/pipeline-model-converter/validate
Imagine running this (or equivalent in elisp) and reporting the result as a flymake/flycheck plugin, hovering over problems with info like:
Unknown stage section "git". Starting with version 0.5, steps in a stage must be in a ‘steps’ block. @ line 10, column 9.
stage('Checkout Code') {
^
WorkflowScript: 10: Expected one of "steps", "stages", or "parallel" for stage "Checkout Code" @ line 10, column 9.
stage('Checkout Code') {
^
I'd like that feature to be in emacs (towards feature-parity with VSCode, yey), and your mode sounds relevant for that, hence my ticket. I'd love to do it myself, but I will likely be distracted (always am) so I guess I am posting this here as FYI, to remind myself, and to share the joy. Feel free to close this as wontfix.
FYI, writing a basic flycheck checker is quite simple (see). In my setup I use the Jenkins declarative linter (aka Jenkinsfile validator) via SSH, therefore I have the following in my init.el:
(flycheck-define-checker jenkinsfile
"A Jenkins declarative pipeline syntax checker using the Jenkins declarative linter.
See URL `https://www.jenkins.io/doc/book/pipeline/development/#linter'."
:command ("ssh" "-p" "16022" "user@localhost" "declarative-linter")
:standard-input t
:error-patterns
((error line-start "WorkflowScript: " line ": " (message) " @ line " line ", column " column "." line-end))
:modes (jenkinsfile-mode groovy-mode)))
Just set the SSH port according to your setup in Jenkins, add your SSH public key and set user@localhost to your username and Jenkins URL.
The error patterns may not be complete, but this should get you started.
+1
I wanted to create a feature request for this but some else beat me to it. Thanks.
@hydev can I use curl in place of ssh?
FYI, writing a basic flycheck checker is quite simple (see). In my setup I use the Jenkins declarative linter (aka Jenkinsfile validator) via SSH, therefore I have the following in my init.el:
(flycheck-define-checker jenkinsfile "A Jenkins declarative pipeline syntax checker using the Jenkins declarative linter. See URL `https://www.jenkins.io/doc/book/pipeline/development/#linter'." :command ("ssh" "-p" "16022" "user@localhost" "declarative-linter") :standard-input t :error-patterns ((error line-start "WorkflowScript: " line ": " (message) " @ line " line ", column " column "." line-end)) :modes (jenkinsfile-mode groovy-mode)))Just set the SSH port according to your setup in Jenkins, add your SSH public key and set
user@localhostto your username and Jenkins URL. The error patterns may not be complete, but this should get you started.
If Someone wants curl alternative for flycheck use this - https://github.com/CsBigDataHub/flycheck-jenkinsfile/blob/master/flycheck-jenkinsfile.el