How to use Jenkins CLI with examples?

How to use Jenkins CLI with examples?

How to use Jenkins CLI with examples?

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In today’s blog post, we will discuss how to install and configure Jenkins cli, how to use Jenkins cli using SSH or jenkins-cli.jar file, how to download jenkins-cli.jar and how to execute Jenkins cli commands with examples.

What is Jenkins CLI?

Jenkins has a built-in command line interface (jenkins-cli) that allows users and administrators to interact with Jenkins in programmatic way. You can access Jenkins cli over SSH or using Jenkins cli client, a jenkins-cli.jar file.

How to use Jenkins CLI with examples?

Prerequisites:

One system with Jenkins installed.

Using Jenkins CLI with SSH:

Step 1: Create a new SSH key in the system from where you want to execute Jenkins cli command.

Step 2: Add the public SSH key to the Jenkins user profile.

Login to Jenkins server and click on the dropdown next to username and click “Configure”.

jenkins-cli.jar

Copy and paste the public key content under “SSH Public Keys” and click “Save”.

jenkins-cli.jar

Step 3: Enable ssh communication to your Jenkins server.

Login to your Jenkins server and navigate to “Configure Global Security” under “Manage Jenkins”.

jenkins-cli.jar

Enable the SSH port and click “Save”.

jenkins-cli.jar

Note: By default, the SSH is disabled in your Jenkins server and even though if you configured the SSH key, it will not work until you enable SSH in your Jenkins server.

Step 4: Configure SSH for your Jenkins keys.

Step 5: Test if you can execute Jenkins cli commands over SSH.

Using Jenkins CLI with CLI client (jenkins-cli.jar file):

Step 1: Download jenkins-cli.jar file

Step 2: Create a Jenkins API token.

Login to Jenkins server and click on the dropdown next to username and click “Configure”.

jenkins-cli.jar

Click “Add new Token” and provide a name to your API token and finally click “Generate” to generate a new API token. Copy store the API token value in a safe place.

jenkins-cli.jar

Step 3: Now test if you can execute Jenkins cli commands using jenkins-cli.jar.

Get Jenkins CLI examples:

You can read the Jenkins CLI documentation from within your Jenkins server. Login to your Jenkins server and click “Manage Jenkins” and then click “Jenkins CLI”.

jenkins-cli.jar

Hope you have enjoyed this article, to get more details on Jenkins, please refer below Jenkins official documentation.

https://www.jenkins.io/doc/

Leave a Reply

Close Menu