Extend the Bluemix Command Line Interface Through Plugins

Share this post:

cloudfoundry_heroAs much as I like nice graphical user interfaces (UIs) and working with the browser, for most tasks I prefer using the command line. I’ve done so—and still do. For working with DB2 and dashDB, I also use the Cloud Foundry (CF) Command Line Interface (CLI) to manage my Bluemix environments. The “cf” tool is quite handy—it allows me to perform what I need to accomplish.

A great feature is its support of plugins, which allow users to extend its functionality. There are IBM-provided plugins and several coming from the Cloud Foundry ecosystem. Below are some brief instructions on how to get started.

Once you’ve installed a recent version of the cf tool, invoking it without any parameters should display some help text on available commands and features. In the lower part of that text should be two sections related to plugins:

Quick overview of CF commands

Below is a quick reference of plug-in repository commands:

  • add-plugin-repo adds a new plugin repository
  • remove-plugin-repo removes a plugin repository
  • list-plugin-repos lists all the added plugin repositories
  • repo-plugins lists all available plugins in specified repository or in all added repositories

And a quick reference of general plug-in commands:

  • plugins lists all available plugin commands
  • install-plugin installs CLI plugin
  • uninstall-plugin uninstalls the plugin defined in command argument


Adding new CF commands via plug-ins

The command add-plugin-repo allows to add new repositories from which plugins can be installed, list-plugin-repos lists those repositories already available in your environment. Try the following two commands to add the plugin repositories from Bluemix Public and from the Cloud Foundry community collection:

cf add-plugin-repo  BluemixPublic
cf add-plugin-repo CF-Community

When done, try the following command to list the repositories. It should return something like this:
henrik>> cf list-plugin-repos

Repo Name Url

With the command repo-plugins it’s possible to list all the available plugins ready to be installed. You can read more about them at the repository descriptions linked above. For switching quickly between my different Bluemix environments I installed the “targets” plugin from the Cloud Foundry community repository:
henrik>> cf install-plugin targets -r CF-Community

Attention: Plugins are binaries written by potentially untrusted authors. Install and use plugins at your own risk.
Do you want to install the plugin targets? (y or n)> y
Looking up 'targets' from repository 'CF-Community'
8230816 bytes downloaded...
Installing plugin /tmp/cf-targets-plugin...
Plugin cf-targets v1.1.0 successfully installed.


After I’m done, when calling just “cf” again, there’s a new section in the help text available:

targets List available targets
set-target Set current target
save-target Save current target
delete-target Delete a saved target


If you have more plugins installed, there will be more commands displayed. Using the “targets” plugin I can save the current environment, i.e., the Bluemix or Cloud Foundry instance I’m logged into, and quickly switch between the Bluemix Dallas (NG) and Bluemix London (EU-GB) platforms using the set-target command. The cf set-target eu command would replace several cf api and cf login commands, and a lot of typing, great for scripting and more efficient work.

Technical Offering Manager / Developer Advocate

More How-tos stories
May 1, 2019

Two Tutorials: Plan, Create, and Update Deployment Environments with Terraform

Multiple environments are pretty common in a project when building a solution. They support the different phases of the development cycle and the slight differences between the environments, like capacity, networking, credentials, and log verbosity. These two tutorials will show you how to manage the environments with Terraform.

Continue reading

April 29, 2019

Transforming Customer Experiences with AI Services (Part 1)

This is an experience from a recent customer engagement on transcribing customer conversations using IBM Watson AI services.

Continue reading

April 26, 2019

Analyze Logs and Monitor the Health of a Kubernetes Application with LogDNA and Sysdig

This post is an excerpt from a tutorial that shows how the IBM Log Analysis with LogDNA service can be used to configure and access logs of a Kubernetes application that is deployed on IBM Cloud.

Continue reading