Description

The bitbucket/pullrequest action opens (or updates) a Bitbucket Cloud pull request once a target linked to the same scm has changed something and the change has been pushed.

It is the second half of the Bitbucket Cloud workflow: the bitbucket scm commits to a working branch and pushes it, this action turns that branch into a pull request. Without it, the branch is pushed and nothing else happens.

For a self-hosted Bitbucket Data Center or Server instance, use stash/pullrequest instead.

Requirements

An action never runs on its own: it needs an scmid pointing at an scm declared in the same manifest, and that scm must be of the matching kind. Both are checked when the manifest loads:

missing value for parameter(s) ["scmid"]
scm of kind "git" is not compatible with action of kind "github/pullrequest"

The action then reuses that scm rather than being configured twice. From it, it inherits:

FieldInherited value

sourcebranch

The working branch the scm created and pushed - the branch carrying the changes.

targetbranch

The scm’s branch - the branch the pull request is opened against.

owner, repository

The repository the scm points at.

credentials, URL

Whatever the scm was given, when the action does not set its own.

Every one of these can be overridden in the action spec, but there is rarely a good reason to: a mismatch between the branch the scm pushed and the branch the action opens the request from produces a request with no changes in it.

Where the title comes from

The title is resolved from the first of these that is set:

  1. spec.title on the action

  2. title on the action itself, one level above spec

  3. the name of the associated target, when there is exactly one

  4. the pipeline name

The second form is the usual one:

actions:
  default:
    kind: <the action kind>
    scmid: default
    title: 'deps: bump axios version'

Create or update

Updatecli looks for a request already open between the same two branches before creating one, so running the same pipeline repeatedly gives you one long-lived request per pipeline and repository rather than one per run. Whether that existing request is then refreshed with the latest title and description differs by plugin (each page says which).

Creation is also skipped, without failing the pipeline, when either branch is missing from the remote. Updatecli attempts it on every run regardless, so that a request closed by hand or lost to an earlier failure gets reopened on the next one.

Pipeline URL

When Updatecli detects that it runs inside a CI job, it appends a link to that job in the request description. Set disablepipelineurl: true on the action (next to kind and scmid, not inside spec) to leave it out.

Detection is limited to three engines, each recognised by one environment variable: Jenkins (JENKINS_URL), GitLab CI (GITLAB_CI), and GitHub Actions (GITHUB_ACTION), checked in that order. Anywhere else no link is added, whatever this setting says.

The credential carried by the scm (a token, or a username with an app password) needs the pullrequest:write scope for this action to work.

Parameters

NameTypeDescriptionRequired
bodystringBody defines the Bitbucket pullrequest body
ownerstringOwner specifies repository owner
passwordstring

“password” specifies the credential used to authenticate with Bitbucket Cloud API, it must be combined with “username”

The “password” should be app password with “pullrequest:write” scope.

“token” and “password” are mutually exclusive

remark: A password is a sensitive information, it’s recommended to not set this value directly in the configuration file but to use an environment variable or a SOPS file.

The value can be set to {{ requiredEnv "BITBUCKET_PASSWORD"}} to retrieve the token from the environment variable BITBUCKET_PASSWORD or {{ .bitbucket.password }} to retrieve the token from a SOPS file.

For more information, about a SOPS file, please refer to the following documentation: https://github.com/getsops/sops

repositorystringRepository specifies the name of a repository for a specific owner
sourcebranchstringSourceBranch specifies the pullrequest source branch
targetbranchstringTargetBranch specifies the pullrequest target branch
titlestringTitle defines the Bitbucket pullrequest title.
tokenstring

“token” specifies the credential used to authenticate with Bitbucket Cloud API

The “token” is a repository or project access token with “pullrequest:write” scope.

“token” and “password” are mutually exclusive

remark: A token is a sensitive information, it’s recommended to not set this value directly in the configuration file but to use an environment variable or a SOPS file.

The value can be set to {{ requiredEnv "BITBUCKET_TOKEN"}} to retrieve the token from the environment variable BITBUCKET_TOKEN or {{ .bitbucket.token }} to retrieve the token from a SOPS file.

For more information, about a SOPS file, please refer to the following documentation: https://github.com/getsops/sops

usernamestring“username” specifies the username used to authenticate with Bitbucket Cloud API

The spec is deliberately small - title and body, on top of the identity fields inherited from the scm. Reviewers, labels, and merge automation are not exposed by this plugin.

body

Replaces the description Updatecli generates from the pipeline run, on creation and on update alike.

An already open pull request is refreshed on each run: Updatecli merges the report of the latest run into the existing description rather than opening a second request.

Cleanup

Cleanup is not implemented for this plugin. updatecli apply --clean-git-branches removes working branches that ended up with no changes, but a pull request already opened for one of them is not closed automatically (that stays a manual step).

The same goes for the options this plugin does not expose, such as reviewers and labels. If closing stale pull requests, or anything else missing here, is something you would use, say so on the Updatecli issue tracker (these gaps are unimplemented rather than deliberate, and interest is what gets them prioritised).

Example

# updatecli.yaml
# updatecli diff --config updatecli.yaml
#
name: Show Bitbucket Cloud pipeline example

# Sources are responsible to fetch information from third location such as npm registry.
sources:
  updatecli:
    name: Get latest axios version
    kind: npm
    spec:
      name: axios

# Targets are responsible to update targeted files such as a yaml file.
targets:
  npm:
    name: Update e2e test file
    kind: yaml
    sourceid: updatecli
    scmid: bitbucket
    spec:
      file: e2e/updatecli.d/success.d/npm.yaml
      key: conditions.axios.spec.version

###

# Actions such as gitlab/mergerequest is triggered if a target is updated.
actions:
  default:
    title: Bump axios version
    kind: bitbucket/pullrequest
    scmid: bitbucket

scms:
  bitbucket:
    kind: bitbucket
    spec:
      owner: "olblak"
      repository: "updatecli"
      branch: main
      # {{ if (env "BITBUCKET_TOKEN") }}
      token: '{{ env "BITBUCKET_TOKEN" }}'
      # {{ else if (and (env "BITBUCKET_USER") (env "BITBUCKET_APP_PASSWORD")) }}
      username: '{{ env "BITBUCKET_USER" }}'
      password: '{{ env "BITBUCKET_APP_PASSWORD" }}'
      # {{ end }}