Develop & Share Your Own JFrog CLI Plugins

JFrog CLI Plugins

If you’re using the JFrog DevOps Platform to manage your software artifacts, then there’s a good chance that one of the clients you’re already using is JFrog CLI. JFrog CLI is a robust tool, which enhances and extends the capabilities of the JFrog Platform, by connecting it to your build and automation agents. JFrog CLI is designed and built for automation, but if you’re like me, and really like using your terminal, JFrog CLI can also serve as a convenient command line tool to query Artifactory for files, builds and metadata.

JFrog CLI Plugins

JFrog CLI has been extended to include JFrog CLI Plugins, which are small applications that can be installed to add new commands to JFrog CLI. The cool thing is that anyone can create a plugin. You now have the freedom to extend an existing capability or add your own. The new commands you add become an integral part of JFrog CLI, alongside the commands JFrog CLI includes out-of-the-box.

What can plugins do?

Almost anything. Since a plugin has access to most of the source code of JFrog CLI and can include new code – either code that you write, or code from external libraries, there’s almost no limit to what you can do. For example, you can create custom upload or download commands for Artifactory, implement your own cleanup policies, modify the output of the existing JFrog CLI commands, integrate with other products, such as issue trackers, send notifications to your team members following a release – you get the idea.

How can I develop my own plugin?

Alright – if I managed to get you excited about this already, you’re probably wondering how this all works. Here’s how – A JFrog CLI Plugin is an independent Go project. The project’s source code is built into a binary, which JFrog CLI assimilates and integrates with. You can see some plugin examples in this GitHub repository. The source code of a plugin can be hosted in any GitHub repository, including repositories that you own and manage.

How does it work?

OK, I guess the next question is how the plugin source code turns into a plugin that can be installed in JFrog CLI. It’s a pretty easy process actually. Let me guide you through the simple steps to do this.

  1. First, install Go version 1.14 or above and also the git client . Make sure both are in your PATH.
  2. Get a GitHub account.
  3. Go to https://github.com/jfrog/jfrog-cli-plugin-template.git
  4. Click on the “Use this template” button to create a new repository. You may name it as you like.
  5. From your terminal, clone your new repository to your local machine. For example:
    $ git clone https://github.com/me/my-amazingi-plugin.git
  6. CD into the new repository you just created.
  7. Build and test your plugin by running the following commands.
    $ go build -o hello-frog
    $ ./hello-frog --help
    $ ./hello-frog hello --help
    $ ./hello-frog hello Yey!

You can now open the project with your favorite IDE and start modifying the template to build your own plugin.

Installing your plugin

Cool! So you have your plugin working as an independent binary. How can it be installed in JFrog CLI? You have two options to choose from.

Option 1: You can install your plugin by simply placing it inside the “plugins” directory under the JFrog CLI home directory. The default location of the home directory is ~/.jfrog but it can be modified using the JFROG_CLI_HOME_DIR environment variable. If there’s no “plugins” directory under .jfrog, simply create it. JFrog CLI automatically picks up and reads the plugins inside this directory. JFrog CLI 1.41.2 or above is supported, so please make sure you don’t use an older version.

Option 2: If you’re thinking big, and you’d like the community to be able install and use your plugin, you also have the option of including your plugin in the JFrog CLI Plugins Registry. All plugins that are included in this registry can be installed using the following JFrog CLI command:

$ jfrog plugin install my-plugin-name

For information on how to include your plugin in the public registry, read the JFrog CLI Plugins Developer Guide.

That’s all for now. I hope I managed to get you excited about the amazing things you can build using JFrog CLI Plugins and also share your work with others. So get to it and create your first JFrog CLI Plugin. Have fun!