If you need something you can’t find a Step for, you can always install and use tools with scripts or Script steps. Add a Script
step to your Workflow, and either write your script there, or run a script from your repository. Passwordless sudo
is enabled in all of our build virtual machines, so you can freely use sudo
if you need it.
Once you have a working script, you can also transform it into a Step and optionally share it with others (through our StepLib). You can find a template and a README about Step creation at our Github page.
Adding a Script Step to a workflow ⚓
- Click your app on the right side of your Dashboard.
- Click the
Workflow
tab to open Workflow Editor. -
Select a workflow in the
WORKFLOW
menu. - Once, you have your workflow, click the
+
sign to insert a Step at that position from our Step Library. - In the
Search steps
bar, search for “script” and click on theScript
Step . This will add the Step to your workflow. - Click the Step in your workflow.
- Insert your script into the
Script content
input field.
Running a script from a repo with Script Step ⚓
If you want to run a script from your repository, you can run it from this Script
Step. Paths are relative to your repository’s root. For example, if you have a Bash script at path/to/script.sh
you can add it to the Script content
input field and run it with the following command:
bash ./path/to/script.sh
Or in a more robust form, which is better if you want to extend the content later:
#!/bin/bash
set -ex
bash ./path/to/script.sh
You can run non-Bash scripts too, for example, a Ruby script:
#!/bin/bash
set -ex
ruby ./path/to/script.rb
Examples for installing dependencies ⚓
Now you have the Script
Step in your Workflow, you just have to write the script to install the dependency. You can do it in the same way as you would on your own Mac / Linux, in your Terminal / Command Line! Let’s see some examples!
brew
on macOS ⚓
For example, to install cmake
with a Script
Step on macOS, use the following brew
command:
#!/bin/bash
set -ex
brew install cmake
The whole Script content
could be as short as:
brew install cmake
This is exactly how you would use brew
on your Mac, but since you’ll most likely add more content to the Script
Step sooner or later, the first example is a more future proof Bash script template.
apt-get
on Linux ⚓
For example, to install cmake
with a Script
Step on Linux, use the following apt-get
command:
#!/bin/bash
set -ex
sudo apt-get install -y cmake
Advanced option: use deps
in bitrise.yml
⚓
Instead of installing your tool inside the Script
Step, you can also use the deps
option of the bitrise.yml
. If you declare deps
for a specific Step, the Bitrise CLI will check if that tool is installed, and will install it for you, if required.
An example, installing cmake
with either apt-get
(where apt-get
is available), or with brew
(on macOS):
deps:
brew:
- name: cmake
apt_get:
- name: cmake
A minimal bitrise.yml
for demonstration:
format_version: 1.2.0
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
workflows:
test:
steps:
- script:
deps:
brew:
- name: cmake
apt_get:
- name: cmake
inputs:
- content: |-
#!/bin/bash
set -ex
which cmake
A minimal bitrise.yml
for demonstration:
format_version: 1.3.0
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
workflows:
test:
steps:
- script:
deps:
brew:
- name: awscli
bin_name: aws
apt_get:
- name: awscli
bin_name: aws
inputs:
- content: |-
#!/bin/bash
set -ex
which aws
Conditional execution ⚓
Additionally, you can use environment variables (env vars) in your scripts too. Here is an example for the PR
env var where we run different scripts for a Pull Request and for a non-Pull Request build:
#!/bin/bash
set -ex
if [[ "$PR" == "true" ]] ; then
echo "=> Pull Request mode/build!"
bash ./path/to/in-case-of-pull-request.sh
else
echo "=> Not Pull Request mode/build!"
bash ./path/to/not-pull-request.sh
fi
Note that you can use any available env var, like the ones exposed by previous steps in the Workflow.