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.jar
file. -
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-number
values as required. -
Save the alias file with an appropriate file name (such as
jenkins-cli.sh
).This alias file assumes that jenkins-cli.jar
is 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_profile
or.bashrc
), which is usually located in your home directory.For example, in your favorite text editor, copy and paste the following line into
.bash_profile
or.bashrc
:alias jenkins-cli='/path/to/jenkins-cli.sh'
-
Edit the
/path/to
value 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_profile
or
-
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 of usage section 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