If you use the Jenkins CLI tool regularly, configure an alias to avoid having to type the entire command each time.
For instance, assuming you’re using Bash:
-
Change to the directory containing the
jenkins-cli.jarfile. -
In your favorite text editor, copy and paste the following into a new "alias" file:
#!/bin/sh java -jar jenkins-cli.jar -auth username:password -s http://operations-center-url:port-number/ "$@" -
Adjust the
username,password,operations-center-url, andport-numbervalues as required. -
Save the alias file with an appropriate file name (such as
jenkins-cli.sh).This alias file assumes that jenkins-cli.jaris located in the same directory. -
Make the alias file executable using the following command.
chmod a+x jenkins-cli.sh -
Configure the actual alias to your alias file in your appropriate Bash configuration file (
.bash_profileor.bashrc), which is usually located in your home directory.For example, in your favorite text editor, copy and paste the following line into
.bash_profileor.bashrc:alias jenkins-cli='/path/to/jenkins-cli.sh' -
Edit the
/path/tovalue as required and save the configuration file. -
Reload your Bash configuration by entering the appropriate command (based on the file you edited).
For example, enter the appropriate command:
-
source ~/.bash_profileor
-
source ~/.bashrc
-
Now, the command jenkins-cli will replace:
java -jar jenkins-cli.jar -auth username:password -s http://operations-center-url:port-number/
Therefore, using this alias, the commands in the examples could be simplified to the following:
-
Listing all available Jenkins CLI tool commands:
jenkins-cli help -
Retrieving the version of your operations center instance:
jenkins-cli version -
Obtaining more information about a specific Jenkins CLI command:
jenkins-cli help plugin-catalog