Using files in your builds

There are multiple ways to use files in your Bitrise builds.

  • Most Steps that generate files store the filepath in an output Environment Variable (Env Var). Subsequent Steps in the same Workflow can re-use that Env Var to access the file.

  • You can upload a file to the Generic File Storage and use the automatically generated Env Var as a Step input value in Steps that accept URLs as an input.

  • You can upload a file to the Generic File Storage and use one of our Steps (for example, the File Downloader Step) to download the file for the build. This works with Steps that require local file paths and as such do not support URLs directly as the input value.

Downloading a file using the File Downloader Step

Once you uploaded a file to the Generic File storage, one of the ways to access it is by using the File Downloader Step. This Step is useful when you need to use a file in a Step input that only accepts local paths as a value.

The Step downloads the file in a location you specify, and then every subsequent Step can access the file in that location.

  1. Open your app on Bitrise.

  2. Go to the Workflow tab.

  3. Go to the Code signing tab and then the Generic File Storage tab.

  4. Find your file and copy the Environment Variable (Env Var) under its filename.

  5. Go to the Workflows tab.

  6. Select a Workflow from the WORKFLOW dropdown menu.

  7. Add the File Downloader Step to your Workflow.

  8. In the Download source url input, paste the Env Var you copied earlier.

  9. In the Download destination path input, specify the path where you want to download the file. It should be a path relative to the root of the repository.

    Using an Env Var as the input value

    You can store the filepath in an App Env Var instead of specifying it directly for the input. That way you can refer to the file through the Env Var in other Steps, you won’t have to specify the path every time.

    For example, if you store the path in the BITRISEIO_MY_FILE_LOCAL_PATH Env Var, you can use it as the path for the input, and also use it to access the file in every subsequent Step.

  10. Click Save in the top right corner.

Downloading a file using a custom Script Step

If you don't want to use the File Downloader Step to download and access an uploaded file in your build, you can use your own custom Script Step as well. All you need to do is to get the download URL and then download the file by specifying a full download path that exists on the build machine.

  1. Open your app on Bitrise.

  2. Go to the Workflow tab.

  3. Go to the Code signing tab and then the Generic File Storage tab.

  4. Find your file and copy the Environment Variable (Env Var) under its filename.

  5. Go to the Workflows tab.

  6. Select a Workflow from the WORKFLOW dropdown menu.

  7. Add a Script Step to your Workflow.

  8. Find the Script content input of the Step.

  9. Add a script to download the file and store the download location in an Env Var.

    In the example below, the download URL is stored in the BITRISE_IO_MY_FILE_ID_URL Env Var. We're using envman to store the local path in the BITRISEIO_MY_FILE_LOCAL_PATH Env Var. Subsequent Steps can use this Env Var to access the file.

    #!/bin/bash
    set -ex
    
    # specify local download path
    export file_local_path=download/path/to/my/file
    
    # download the file
    wget -O "$file_local_path" "$BITRISEIO_MY_FILE_ID_URL"
    echo "file downloaded to: $file_local_path"
    
    # OPTIONALLY: export the file's local path, to be able to use it in subsequent steps as an input value
    envman add --key BITRISEIO_MY_FILE_LOCAL_PATH --value "$file_local_path"

    Alternatively, for example, you can set the location as an App Env Var and simply download it to that path instead of defining the path inside the Script Step.