Skip to main content

Using files in your builds

Abstract

To use a file in your builds, you can download it using a Step like File Downloader in your Workflow, or you can use the file's automatically generated Env Var as a Step input.

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

One of the ways to access a file in your build 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.

Workflow Editor

bitrise.yml

  1. Open the Workflow Editor.

  2. Add the File Downloader Step to your Workflow.

  3. In the Download source url input, add the location where the file can be found.

    Finding the download URL for an uploaded file

    If you uploaded the file to Bitrise, you can find its download URL in the Files section of the App settings page.

  4. 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.

  5. Click Save in the top right corner.

  1. Open the app's bitrise.yml file.

  2. Add the file-downloader Step to your Workflow.

    workflows:
      download:
        steps:
        - activate-ssh-key: {}
        - git-clone: {}
        - file-downloader:
            inputs:
    
  3. In the source input, add the location where the file can be found.

    workflows:
      download:
        steps:
        - activate-ssh-key: {}
        - git-clone: {}
        - file-downloader:
            inputs:
            - source: "$BITRISEIO_BITRISE_TEST_URL"
    
  4. In the destination input, specify the path where you want to download the file. It should be a path relative to the root of the repository.

    workflows:
      download:
        steps:
        - activate-ssh-key: {}
        - git-clone: {}
        - file-downloader:
            inputs:
            - destination: "/"
            - source: "$BITRISEIO_BITRISE_TEST_URL"
        - deploy-to-bitrise-io: {}

    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.

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.

Workflow Editor

bitrise.yml

  1. Log in to Bitrise and select Bitrise CI on the left, then select your app.

  2. Click the Workflows button on the main page.

  3. Add a Script Step to your Workflow.

  4. Find the Script content input of the Step.

  5. Add a script to download the file and store the destination path in an Env Var.

    Uploading the file to Bitrise

    If you upload the file to Bitrise, you can use the file's download URL in your script.

    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 destination 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.

  1. Open the bitrise.yml file of your app.

  2. Add a script Step to your Workflow.

    my-workflow:
      steps:
        script:
          inputs:
          - content:
  3. In the content input, add a script to download the file and store the destination path in an Env Var.

    Uploading the file to Bitrise

    If you upload the file to Bitrise, you can use the file's download URL in your script.

    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 destination path in the BITRISEIO_MY_FILE_LOCAL_PATH Env Var. Subsequent Steps can use this Env Var to access the file.

    my-workflow:
      steps:
        - script:
            inputs:
            - content:
            #!/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"
    

    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.

  4. Optionally, export the file's local path so you can use it in subsequent Steps in the same Workflow.

    my-workflow:
      steps:
        - script:
            inputs:
            - content:
            #!/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"
    
            # export the file path for subsequent steps
            envman add --key BITRISEIO_MY_FILE_LOCAL_PATH --value "$file_local_path"