Bitrise CLI: explore Bitrise from your terminal and start creating awesome apps

This Bitrise CLI tutorial will show you how to build, test, optimize and run your workflows while saving credits from your terminal. Read on to learn more!

CLI or Command Line Interface is one of developers favorite tools because it’s quicker and easier to do tasks outside of the IDE. Because we care about our developers and we’re always eager to help them, we introduced Bitrise CLI. It brings Bitrise Workflows to your fingertips to be able to run, configure and test your Workflows easily on your local machine. 

What’s Bitrise CLI?

Bitrise CLI is a Command Line Interface for running your Workflows on your local machine or even automating your local development processes (or almost anything) with a single terminal command. 

The pre-requisites

For macOS it’s pretty easy: you only need to install Homebrew first. And if you're on Linux or want to install bitrise without using homebrew, check out the install instructions on CLI's releases page. It's as simple as downloading the binary and don’t forget to chmod +x it.

Install, setup, and update Bitrise CLI

macOS 

We’ve made it so easy for you. No need to download anything, just one command and you can reach the final frontier!

brew update && brew install bitrise
Copy code

M1 machine:

If you are installing the CLI from the source. please note by default /usr/local/bin does not exist for M1 machines, you should use a custom folder or save it to your bin folder. i.e /opt/.But installing it with Homebrew puts the binary into the correct path.

Linux

To install the latest version (current version is 1.48.0) from the release page, run the following commands (in a bash shell):

curl -fL https://github.com/bitrise-io/bitrise/releases/download/1.48.0/bitrise-"$(uname -s)"-"$(uname -m)" > /usr/local/bin/bitrise
Copy code

Then: 

chmod +x /usr/local/bin/bitrise
Copy code

After that, you can run a bitrise setup command. This will verify if everything that is required for Bitrise to run is installed and available. If you skip this, the CLI will perform the setup anyway the first time you call the bitrise run command.

Updating the Bitrise CLI is easy, and it doesn’t matter if you installed it with Homebrew or from the GitHub releases.

Simply run the bitrise update command that’s it! The CLI checks for updates once every day and notifies you as soon as there is a new version.

That's all, you're ready to call bitrise! 🚀

Getting started with Bitrise CLI

With Bitrise CLI we can do different things such as add a new app, configure the workflow yml files or create a new Bitrise Integration step. Let’s have a look!

Note: In general, to use the CLI locally, you don't need a Bitrise account, you just need to install the CLI but in case you need to add a new app you need the following: 

  • A Bitrise account, with a connected Git provider.
  • The project must have a local Git repository on your machine and a remote repository at a Git provider. If you want to use an SSH key to access the repository, the remote repository URL must be an SSH URL! For example, git@github.com:example-user/example.git.

Adding a new app from a CLI

You can add a new app from the CLI using the following steps: 

  • Login to Bitrise using your account credentials.
  • From your Dashboard, click on add new app and select CLI
  • Select the privacy setting, it’s private by default. 
  • Copy the curl command you find there.
  • Open a command-line interface.
  • Change the directory to your project’s location.
  • Paste the curl command and click Enter.
  • Continue with the wizard and choose your preferred options
  • If everything went well, the project will be created successfully with the URL of the app on Bitrise.
  • Copy and paste the URL and you will notice that the app was added successfully and the first build already triggered. 🎉
  • And like adding apps from the bitrise.io, the build will consume from the team credit. 

Initializing a Bitrise project locally

Another option or feature with Bitrise CLI is that you can initialize the Bitrise app/project locally by the following steps: 

For the prerequisites check our documentation. 

  • Open a command-line interface.
  • Change the directory to your project’s location.
  • Run bitrise init command.
  • The scanner will detect the platform type.
  • The Bitrise configuration files will be generated like this:

Including: 

  • bitrise.yml: The workflow yaml file includes the Bitrise steps.
  • .bitirse.secrets.yml: To store your secrets for your app.

Bitrise CLI includes different commands you can use to manage your Workflows:

For instance, you can run the bitrise validate command to check the yml files.

Update the Workflow Editor offline

Bitrise Workflow Editor is designed in such a way that you can run it offline on your machine without having to log into bitrise.io. The Workflow Editor is open source, you can find its repository here. By running the following command into a directory where you have your bitrise.yml:  

bitrise :workflow-editor

The command will open a local Bitrise Workflow in the browser, then you can update the Workflows, Secrets, Environment Variables and the Triggers and save all of these changes easily. 

In the command line, you will notice all the actions that you are doing in the web session displaying as API calls.  

For instance, you can check the Trigger map and add the workflow to run for every pull request and save the changes. 

Once you close the Workflow Editor session from the browser, you will notice that the session is deleted.

Note: You can upgrade to the latest version of the Workflow Editor by running the following command: 

bitrise plugin update workflow-editor

Run the Bitrise build locally

You can also run a specific workflow using the following command: 

bitrise run primary

You will notice that some of the Steps will be skipped because the Run-If expression was .IsCI | and (not .IsRP) but other Steps such as android-unit-test will run successfully. 

Environment Variables

You can set your own Env Vars but there is a selection of Env Vars that are exposed automatically by either the Bitrise CLI or bitrise.io.

Env Vars exposed by the Bitrise CLI are available everywhere, even if you run the build on your own computer. The Env Vars exposed by bitrise.io are available for builds running on bitrise.io virtual machines. Because of that, you need to define these Env Vars locally, especially the Secret Vars to get a successful workflow. Bitrise CLI has support for reading the secrets from the .bitirse.secrets.yml file. 

Important Note

When you run the Workflow after establishing it locally, you don't need a Bitrise account, so you can update, maintain, and do all the things necessary for a workflow without consuming any credits. Otherwise, if you push the project and connect it to a Bitrise account, or add the new app via CLI, your credits will be affected and builds will consume credits.

Creating a new Step 

Another feature of the Bitrise CLI that you can use to create a new Bitrise Step. Bitrise has +350 open-source Steps and integrations. In case you need to create a new one, you can do it easily and submit it to the Bitrise Step Library. More information can be found in our detailed article

Summary

Bitrise CLI helps you to run the Bitrise Workflows on your Mac or Linux local machine or even automate your local development processes such as building, testing, optimizing, and running the workflows with a single terminal command. Using the CLI will save your credit by verifying that your Workflows are working properly on your local machine before pushing and running the apps on bitrise.io.  

Thank you for reading and happy building 👨🏻‍💻

Further Reading

No items found.
The Mobile DevOps Newsletter

Explore more topics

App development

Best practices from engineers on how to use Bitrise to build better apps, faster.

Community

Meet other Bitrise engineers, technology experts, power users, partners and join our BUGs.

Company

All the updates about Bitrise events, sponsorships, employees, and more.

Insights

Mobile development, latest tech, industry insights, and interviews with experts.

Mobile DevOps

Learn why mobile development is unique and requires a set of unique practices.

Releases

Stay tuned for the last updates, new features, and product improvements.

The Mobile DevOps Newsletter

Join 1000s of your peers. Sign up to receive Mobile DevOps tips, news, and best practice guides once every two weeks.