Set up remote access

Remote access is currently in Beta for Cloud and only available to Linux cloud runtimes

Remote access provides a connection to an HTTP service running inside your step. The services you choose to run and connect to, such as editors, terminals, or application previews, and how you configure and secure them are your responsibility. Issues with those services, your custom configuration, or your specific use case are outside the scope of Bitbucket Support. If you have a feature request or have identified a bug while using remote access itself, share it in the Atlassian Community.

Remote access lets you connect to a service running inside a Bitbucket Pipelines step while the pipeline is running. In order to connect remote access to service, add a remote-access declaration to the script or after-script of a step. When the step reaches the declaration, it waits, and you can connect to the HTTP service that is exposed from the step, or just continue the step.

Anything that speaks HTTP works with remote access, including WebSockets, so you can connect to a browser-based editor, a terminal, or a preview of an application running in the step.

Note: Remote access is designed for situational debugging, for example when you have an edge case you cannot figure out, or an issue with the pipeline environment itself. It is not intended to be left on for every step.

In order to use remote access, it must be enabled in both your workspace or repository settings by an admin, and a remote-access declaration has to be added to a step.

Enable Remote Access

Remote Access is disabled by default, and must be enabled in both workspace settings and repository settings. Afterwards, you can configure your pipeline to use Remote Access.

Enable Remote Access for your workspace

Select the Settings cog on the top navigation bar, then select Workspace settings. Select Pipelines on the left sidebar, and then select Remote access. Select the Remote access toggle to allow repositories to enable remote access.

Note: If you disable Remote Access for the workspace, the setting is reset to disabled for all repositories in the workspace.

Enable Remote Access for your repository

Next to the name of your repository in the left sidebar, select More actions (…), and then select Settings. Select Pipelines on the left sidebar, and then select Remote access. Select the Remote access toggle to allow repositories to enable remote access.

Configure a pipeline with Remote Access

Add a remote-access declaration to the script or after-script of a step. When the step reaches the declaration, it waits until you connect to the service or you can continue the step.

Before the declaration, start the service that you want to connect to, which should be listening on the port that you specify in the declaration. Run the service in the background, for example by adding & to the command, so that the script can continue to the declaration.

pipelines: default: - step: name: Run app script: # Start your service in the background, listening on port 8080 - ./app.sh --port 8080 & - remote-access: name: app port: 8080 type: http

The remote-access declaration requires three properties:

  • name: A label for the session. It is shown in the pipeline log.

  • port: The port, inside the build container of the step, that your service listens on. Use an integer between 1 and 65535.

  • type: The type of traffic to expose. http is the only supported value.

For more information about these properties, see remote-access in Step options.

Keep the following in mind:

  • A step can only define a single remote-access declaration, across both script and after-script. To connect to more than one service, use separate steps.

  • Make sure that your service is ready to accept requests before the step reaches the declaration.

  • The step waits at the declaration until you select Continue step, stop the pipeline, or the max-time of the step elapses. See the Billing section below.

  • To connect to a step after a failure, add the declaration to after-script. See the after-script example below.

Using Remote Access

When a step reaches a remote-access declaration, the step enters the “Awaiting Connection” status. At this point, users with write access to the repository can either Connect to the Remote Access session, or Continue step.

Selecting Connect opens a dialog that shows the URL and access token for the Remote Access session, an example curl command, and an Open in Browser button.

Connect to a step

The Connect dialog gives you two ways to connect to the Remote Access session: programmatically, using the URL and access token, or from your browser, using Open in Browser.

Connect programmatically

Use the URL and access token shown in the dialog to connect from a script or command line. The dialog includes an example curl command that uses both to make a request to the Remote Access session. For programmatic access, the token must be presented on every request via an Authorization: Bearer <token> header.

Connect from your browser

Select Open in Browser in the dialog to open the Remote Access session in your browser. You are redirected to the Remote Access session, where you are logged in via a session cookie unique to that session. Once logged in, you are redirected to / of the application running on the Remote Access port over HTTPS.

Continue the step

Selecting Continue step moves the step on from the remote-access declaration. The Remote Access session is torn down, and any users that were connected lose access to the session.

Stopping the pipeline works exactly as it does today: the build is stopped and any Remote Access sessions are closed automatically. Remote Access sessions are ephemeral: a session is torn down when you continue the step or stop the pipeline.

Examples

Copy any of the following examples into your bitbucket-pipelines.yml file and run the pipeline. The step waits at the remote-access declaration. To resume the step, select Continue step.

Example — using remote access to run a browser-based terminal

Starts a browser-based tty, allowing shell commands to be executed directly within the step. Run the pipeline, then select Connect, and then select Open in Browser to launch the editor.

pipelines: custom: remote-terminal: - step: name: Remote Terminal Demo image: ubuntu:22.04 script: # Install ttyd - > apt-get update && apt-get install -y ttyd # Launch ttyd - > ttyd -p 7681 -W bash --norc & - remote-access: name: server port: 7681 type: http # Run any commands you want to run after continuing the remote access session here.

Example — using remote access to preview an application

Starts the development server of your application in the background. Select Connect, and then select Open in Browser to open the application in a new tab.

pipelines: custom: app-preview: - step: name: App preview image: node:24 script: # Run any necessary setup steps before remote-access # Make sure the application is available on port 8080 - npm start & - remote-access: name: app-preview port: 8080 type: http

Example — using remote access in the after-script option to investigate a failed step

The after-script option runs whether or not the script succeeds. To investigate a step that has failed, add the remote-access declaration to after-script, so that the step waits after the failure and you can connect to it.

pipelines: default: - step: name: Build and test image: ubuntu:24.04 script: - ./build.sh after-script: # Start ttyd on port 7681 so that you can inspect the step - apt-get update && apt-get install -y ttyd - ttyd --port 7681 -W bash --norc & - remote-access: name: terminal port: 7681 type: http

Billing

Steps that use Remote Access are charged as per any other running step, at the same rate that the step is billed at. A step that is “Awaiting Connection” is still running, so it incurs build minutes charges in accordance with the step size and any other multipliers applied to the step. Using Remote Access does not change how build minutes are calculated.

A step that is waiting continues to wait until you select Continue step or stop the pipeline. If neither happens, the step waits until its max-time elapses, at which point the Remote Access session is closed automatically, as for a normal timeout. Waiting time counts against the max-time of the step, so set a max-time you are comfortable with, and avoid leaving steps waiting when you are not using them.

Security

Access

Connecting to a Remote Access session is restricted to users with repository write permissions.

While a step is waiting at a remote-access declaration, periodic checks are performed to ensure that Remote Access is still enabled for the repository and workspace, and that any connected users still have write access to the repository. If any of these conditions cannot be met, the step is failed and the Remote Access session is torn down within 5 minutes.

Authentication and authorization

The Remote Access token is a secret and must be protected. Treat it like any other credential, and avoid committing it or sharing it with other users.

Access to a Remote Access session is protected by a token that must be presented on every request. For programmatic access, present the token in the Authorization: Bearer <token> header. For browser access, a session cookie associated with that Remote Access session carries the token.

Browser access must be done using the Open in Browser button after selecting Connect. This sets up the session cookie containing the token that grants access to the Remote Access session.

The token's lifetime is set to the max-time of the step plus a small buffer.

Secured variables

A user who is connected to a Remote Access session can see the secured variables available to the step. For example, if you expose a terminal from the step, a connected user can print secured variables using commands such as env. Only expose services you trust, and remember that any user with write permission to the repository can connect to a Remote Access session.

Limitations

  • Remote Access can only be enabled by workspace admins (at the workspace level) and repository admins (at the repository level).

  • Remote Access is disabled by default for workspaces and repositories.

  • Remote Access is only available to paid users with established billing.

  • Remote Access is only available on the Linux cloud runtime. Self-hosted runners are not supported.

  • Remote Access cannot be used on deployment steps.

  • A user must have write permission to a repository to connect to a Remote Access session.

  • A step can only define a single remote-access declaration, across both script and after-script.

  • Only HTTP can be exposed, including WebSockets. To expose non-HTTP traffic (for example, raw TCP), tunnel it over a WebSocket using a tool such as wstunnel.

  • If a connected user loses write access, or Remote Access is disabled while a step is waiting, the step is failed and the Remote Access session is torn down within 5 minutes.

  • The build container must have mkfifo, echo and read installed. This is typically an issue when using a very minimal container image.

Troubleshoot Remote Access

This page describes common problems when using Remote Access, and how to resolve them. For setup and usage.

Pipeline configuration errors

These errors are shown when the pipeline is created or when the step reaches the remote-access declaration.

Message

Cause

How to resolve

Remote Access is disabled in your workspace

Remote Access is not enabled for the workspace.

Enable Remote Access in your Workspace settings.

Remote Access is disabled in your repository

 

Enable Remote Access in your and Repository settings. If you disable Remote Access for the workspace, the setting is reset to disabled for all repositories, so enable it for each repository again.

Remote access is currently restricted to trusted paid users.

Remote Access is only available to paid users with established billing.

Check that your workspace is on a paid plan and that billing is established.

Remote access is not allowed when using deployment.

The remote-access declaration is in a deployment step.

Remote Access cannot be used on deployment steps. Move the declaration to a step that is not a deployment step.

The Remote Access feature is not supported on this runner's platform.

The step runs on a runner that does not support Remote Access.

Remote Access is only available on the Linux cloud runtime. Self-hosted runners are not supported. Run the step on the Linux cloud runtime.

A maximum of 1 remote-access declaration can be defined per step across script and after-script

A step contains more than one remote-access declaration.

Remove the extra declarations, or move each one to a separate step. A step can only define a single declaration, across both script and after-script.

Missing or empty remote-access name.

The name property is missing or empty.

Add a name to the declaration.

Missing or empty remote-access type.

The type property is missing or empty.

Add type: http to the declaration.

Invalid remote-access type '<type>'. The only supported value is 'HTTP'.

The type is not http.

Set type: http. To expose other traffic, such as raw TCP, tunnel it over a WebSocket (see Limitations).

Invalid remote-access port. The port must be between 1 and 65535.

The port is outside the valid range, or is not an integer.

Set port to the integer port that your service listens on, between 1 and 65535.

A participant in the remote access session no longer has write access to this repository. Ask a repository administrator to restore access, then rerun the pipeline.

A user who previously connected to a Remote Access session in this step no longer has repository write access. The session is torn down within 5 minutes of their access being revoked.

Rerun the step, or remove the remote-access declaration if it is no longer needed. If the participant needs to reconnect, ask a repository administrator to restore their write access.

You cannot find the Remote Access setting

If Remote Access is not shown under Pipelines in your workspace or repository settings, check that you are a workspace admin (for workspace settings) or a repository admin (for repository settings). Only admins can enable Remote Access.

The step does not wait at the declaration

The step only waits when it reaches the remote-access declaration. Check that the commands before the declaration succeed. If a command in script fails, the script stops before it reaches the declaration. To connect to a step after a failure, put the declaration in after-script, which runs whether or not the script succeeds.

Problems connecting to a session

Symptom

Cause

How to resolve

You receive an HTTP 404 when connecting to the session.

You do not have write permission to the repository, or the session has ended. A session ends when the step continues, the pipeline is stopped, the step times out, or the step fails.

Ask a repository admin for write permission. If the session has ended, run the pipeline again and connect to the new session.

You receive an HTTP 404 while logging in after selecting Open in Browser.

Your write permission to the repository was removed, or the session has ended.

Check that you still have write permission, then run the pipeline again if the session has ended.

You receive an HTTP 503 when connecting to the session.

Nothing is listening on the port in the remote-access declaration, inside the step.

Check that your service is running and listening on the declared port before the step reaches the declaration. Start the service in the background, and wait until it is ready.

Requests from a script or curl are rejected.

The token is missing, or is no longer valid. The token must be presented on every request.

Send the token in the Authorization: Bearer <token> header. The token's lifetime is the max-time of the step plus a small buffer.

The step fails while you are connected, or the session closes unexpectedly.

While a step is waiting, periodic checks make sure that Remote Access is still enabled for the repository and workspace, and that connected users still have write access. If any of these conditions are no longer met, the step is failed and the session is torn down within 5 minutes.

Re-enable Remote Access, or restore write permission, then run the pipeline again.

Problems with steps, time and build minutes

Symptom

Cause

How to resolve

A step stays in the "Awaiting Connection" status and uses build minutes.

The step is waiting at the remote-access declaration. A waiting step is still running, so it is charged build minutes.

Select Continue step, or stop the pipeline. If you do neither, the step waits until its max-time elapses. Set a max-time that you are comfortable with.

The step times out while you are connected.

Time spent waiting and connected counts against the max-time of the step. When it elapses, the step times out and the session is closed.

Increase the max-time of the step, and run the pipeline again.

Remote Access does not work with a minimal build image.

The build container must have mkfifo, echo and read installed.

Use an image that includes these commands, or install them in the step before the declaration.

Authorization checks

Periodic checks are perform to ensure remote access is still enabled in the workspace or repository, and that any users connected to a session still have repository access. The following errors are displayed where an authorization check fails.

Symptom

Cause

How to resolve

A participant in the remote access session no longer has write access to this repository. Ask a repository administrator to restore access, then rerun the pipeline.

A user who previously connected to a Remote Access session in this step no longer has repository write access. The session is torn down within 5 minutes of their access being revoked.

Rerun the step, or remove the remote-access declaration if it is no longer needed. If the participant needs to reconnect, ask a repository administrator to restore their write access.

Remote access could not be authorized. Check if it is enabled for your repository and if you have the required permissions.

Remote access was disabled at either the workspace or repository level after a pipeline was triggered, but before reaching the Remote Access declaration.

Re-enable Remote Access and re-run the step.

Remote access is disabled in this repository. Ask a repository administrator to enable remote access, then rerun the pipeline.

Remote Access was disabled for the repository whilst waiting at a declaration.

Re-enable Remote Access and re-run the step.

Remote access is disabled in this workspace. Ask a workspace administrator to enable remote access, then rerun the pipeline.

Remote Access was disabled for the workspace whilst waiting at a declaration.

Re-enable Remote Access and re-run the step.

 

Still need help?

The Atlassian Community is here for you.