How can I pipe Jenkins from the command line?
It looks like there are two options for drawing pipeline scripts, one via the cli on the leader or the http POST call:
CLI reuse with SSH
# ssh (Jenkins CLI)
# JENKINS_SSHD_PORT=[sshd port on master]
# JENKINS_HOSTNAME=[Jenkins master hostname]
ssh -p $JENKINS_SSHD_PORT $JENKINS_HOSTNAME declarative-linter < Jenkinsfile
Reuse over HTTP POST with curl
# curl (REST API)
# Assuming "anonymous read access" has been enabled on your Jenkins instance.
# JENKINS_URL=[root URL of Jenkins master]
# JENKINS_CRUMB is needed if your Jenkins master has CRSF protection enabled as it should
JENKINS_CRUMB=`curl "$JENKINS_URL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)"`
curl -X POST -H $JENKINS_CRUMB -F "jenkinsfile=<Jenkinsfile" $JENKINS_URL/pipeline-model-converter/validate
source to share
HTTP without crumbs.
If you want to use HTTP and don't want to use CRUMB. just add your username and password using the [-u 'option. Replace <username> and <password> with your username and password. Also check if the jenkins server url is correct.
curl --user <username>:<password> -X POST -F "jenkinsfile=<Jenkinsfile" http://localhost:8080/pipeline-model-converter/validate
source to share
In addition to kongkoro's answer, there is a Jenkins file overlay tool.
https://www.npmjs.com/package/jflint
# install
$ npm install -g
# usage
# JENKINS_URL=[root URL of Jenkins master]
$ jflint -j $JENKINS_URL Jenkinsfile
What jflint does is the same as curl in the official doc , while jflint only works with declarative pipelines. But it's easier to use.
source to share
There is also a tool for Sublime Text that takes the SSH method and makes it simple.
https://github.com/june07/sublime-Jenkinsfile/blob/master/README.md
source to share