There are many answers to this question but my question is slightly different.
What I tried
java -jar jenkins-cli.jar -s http://<user>:<API_Token>@server get-job myjob > myjob.xml
java -jar jenkins-cli.jar -s http://<user>:<password>@server get-job myjob > myjob.xml
But I got the error anonymous
user error. So, how can authenticate user using jenkins-cli.jar command ?
hudson.security.AccessDeniedException2: anonymous is missing the Job/ExtendedRead permission
at hudson.security.ACL.checkPermission(ACL.java:63)
I also tried,
$ curl -u <user>:<API_Token> http://server/ get-job myjob > myjob.xml
But, the it just dumps whole HTML page instead of job.xml file
You may sometimes need to log in first:
java -jar jenkins-cli.jar -noCertificateCheck -s https://localhost login --username=exporter --password=mypass
java -jar jenkins-cli.jar -noCertificateCheck -s https://localhost list-jobs
java -jar jenkins-cli.jar -noCertificateCheck -s https://localhost get-job myjob > myjob.xml