Streamline your container workflow with Codefresh!

Introducing the Codefresh CLI

Codefresh News | January 23, 2018

Today we’re releasing a new CLI (Command Line Interface) tool to give engineers even more options for how they access and use Codefresh. In addition to exposing the features already available in Codefresh, the CLI unlocks a number of advanced features such as running parallel pipelines, waiting for pipelines to reach a desired state, searching all connected image registries and more! Here’s how to get started and try some of the features.

The CLI exposes the Codefresh API both for your local machine and inside of Codefresh pipelines. 

Installing Codefresh CLI Locally and Authenticating

Install the command line

You can download the latest executable from the project’s GitHub, under “Releases”.
Alternatively, you can get it using npm/yarn package managers:

With NPM:  npm install -g codefresh
With Yarn:  yarn global add codefresh

For the pros among you, we even provide shell completions:

Linux:  /usr/local/bin/codefresh completion >> ~/.bashrc
OS X:  /usr/local/bin/codefresh completion >> ~/.bash_profile

Authenticate

First create an API key by going to your account settings, under “Tokens”, and generating a new API key.

Then authenticate by running  codefresh auth create-context --api-key {API_KEY}.

Using CLI in Codefresh Pipelines

If you use the Codefresh CLI in a pipeline step, it will be already configured, authenticated, and ready for use. No additional authentication is required!

As example, in this custom pipeline step we can use the CLI to fetch the Helm registry url and load it into a variable for use in later steps.

Codefresh CLI Examples

You can now get info on possible commands by running  codefresh --help , which will output something like this:

As you can see, Codefresh follows a {verb} {noun} syntax and additional information about each command is available by running

Get and Run Pipelines

Lets see all our pipelines.

Now we can run pipelines using their ID and specifying the repo branch you’re working from.

Get images and add annotations

Since you can add multiple Docker registries to Codefresh, you can access all of them and manipulate annotations.

Lets add some annotations and information to these images so it’ll show up in the UI.

This will then show up in the UI. You can read the image annotations documentation here.

Running Matrix Pipelines

Matrix pipelines allow you to use a single pipeline to trigger tens of workflows with different variables. For example, lets say you were building different docker images for node.js where you watch to swap Dockerfiles but keep the same pipeline. First we’d create a variables file containing our different variables. You can use json, or yaml. I’ll name this variables file  node-releases.yml

Then we’ll run our matrix pipeline specifying that we want to wait until all of these workflows have completed before moving on.

Many more options

There are many many more commands and options for you to play with. The best thing about the CLI is that it’s self-documented. Just add --help whenever you’re in doubt. Feel free to explore the CLI and discover more things to do with it!

Conclusion

The Codefresh CLI opens up a lot of possibilities for working with pipelines and images. Since Codefresh is multi-tenancy by default, you can even switch contexts between accounts as needed! We’re excited to see what you build. To try it out, just create a free account, and follow the instructions at the top of this post.

Important Links

Documentation

Report Issues

Follow the Github project

About Dan Garfield

Dan is a full-stack web developer and VP of the Marketing at Codefresh. Dan is a *nix native and all around technology enthusiast.

Reader Interactions

Enjoy this article? Don't forget to share.

Comments

Your email address will not be published. Required fields are marked *

Follow me on Twitter