Basics of Jenkins CLI

Basics of Jenkins CLI

Prerequisite:

  1. Ubuntu OS
  2. Java installed. You can use jabba to install specific version

Basics of using Jenkins CLI:

  1. Jenkins CLI documentation can be accessed through the following URL address: http://[jenkins_url]:8080/cli
  2. To use Jenkins CLI you can download the executable jar file from the following URL address: http://[jenkins_url]:8080/jnlpJars/jenkins-cli.jar
  3. To authenticate Jenkins CLI commands against the server you can create a token or use an existing one. The token is generated at: http://[jenkins_url]:8080/user/[username]/configure or via User profile --> Configure:
  4. To list existing Jenkins jobs use the following command:
    java -jar jenkins-cli.jar -auth [username]:[token] -s http://[jenkins_url]:8080 list-jobs
    
  5. To get help on command use:
    java -jar jenkins-cli.jar -auth [username]:[token] -s http://[jenkins_url]:8080 help [subcommand]
    
  6. To build the job with verbosity mode set use:
    java -jar jenkins-cli.jar -auth [username]:[token] -s http://[jenkins_url]:8080 build [job_name] -s -v
    
  7. To delete job use:
    java -jar jenkins-cli.jar -auth [username]:[token] -s http://[jenkins_url]:8080 delete-job [job_name]
    

Build-in Jenkins variables:

To get the list of all available built-in Jenkins variables use: https://[jenkins_url]:[port_number]/env-vars.html/

Reference:

Jenkins CLI