Skip to main content
Last Reviewed: June 08, 2023

Authenticate Terminus in a Bitbucket CI Pipeline

Learn how to authenticate Terminus in a Bitbucket CI pipeline without receiving errors.

This section provides information on how to to authenticate Terminus in a Bitbucket CI pipeline without receiving errors and avoiding authentication rate limits.

Caching Authentication for Bitbucket Pipelines

You can use the example script in this section for a full start-to-finish Terminus authentication in Bitbucket. This pipeline does the following:

  • Uses the ubuntu:latest Docker image.
  • Performs git clone to checkout the code from the repository.
  • Updates the system and installs necessary tools like PHP, curl, perl, sudo, and Git.
  • Determines the latest release of Terminus from the GitHub API and stores it in the TERMINUS_RELEASE variable.
  • Creates a directory for Terminus, downloads it into that directory, makes it executable, and then creates a symbolic link to it in /usr/local/bin so that you can run it from anywhere.
  • Exports the TERMINUS_TOKEN environment variable (assuming that you've already set it in your pipeline settings) and uses it to authenticate Terminus.
  • Checks that Terminus is authenticated with terminus auth:whoami.
  • Defines a cache for the $HOME/.terminus directory. The pipeline system will save and restore the cache for subsequent runs.

Before you use this script:

  • Ensure that you have defined TERMINUS_TOKEN in Bitbucket Pipeline's Environment Variables.
  • Replace ${TERMINUS_TOKEN} in the script below with the machine token provided by Terminus.
  • Add the the machine token provided by Terminus to your environment variables in the Bitbucket pipeline settings.

image: ubuntu:latest

    - step:
        name: Install and Configure PHP and Terminus
          - apt-get update
          - apt-get install -y php curl perl sudo git jq
          - git clone $BITBUCKET_CLONE_URL .
          - export TERMINUS_RELEASE=$(curl --silent "" | jq -r .tag_name)
          - mkdir ~/terminus && cd ~/terminus
          - echo "Installing Terminus v$TERMINUS_RELEASE"
          - curl -L$TERMINUS_RELEASE/terminus.phar --output terminus
          - chmod +x terminus
          - sudo ln -s ~/terminus/terminus /usr/local/bin/terminus
          - terminus auth:login || terminus auth:login --machine-token="${TERMINUS_TOKEN}"
          - terminus auth:whoami
          - terminus

    terminus: $HOME/.terminus