CaC - Cheat Sheet

Rule structure

A CaC file contains repository rules in a top-level rules section.

YAML
rules:
  - ...

Each entry in the rules list is a complete Process Guardian rule.

Anatomy of a rule

Each rule defines when it runs, what it validates, and under which conditions it applies.

YAML
rules:
  - title: "My rule"
    error: "Validation failed"
    hint: "Resolve the issue before merging"
    success: "Validation passed"
    description: "Optional rule description"
    enabled: true
    triggers: [PULL_REQUEST]
    target: [COMMITS, BRANCH]
    strategy: all

    checks:
      ...

    conditions:
      ...

Rule metadata

Field

Description

title

Human-readable name of the rule.

REQUIRED

error

Message shown when the rule fails.

REQUIRED

hint

Additional guidance shown alongside a failure.

success

Optional message shown when the rule passes.

description

Optional documentation text for the rule.

enabled

Enables or disables the rule. Defaults to true.

triggers

Triggers define which lifecycle events execute the rule.

REQUIRED

target

Targets define which artifacts are inspected by a rule.

REQUIRED

checks

Checks define what is validated when the rule runs.

REQUIRED

Triggers

Triggers define which lifecycle events execute the rule.

Trigger

Description

PULL_REQUEST

Executes the rule during pull request validation.

COMMIT

Executes the rule during commit validation through the Validation API.

PUSH

Executes the rule during push validation through the Validation API.

Important: Commit and Push validation are available through the Validation API, for example using local Git hooks, CI/CD pipelines, or custom integrations. Bitbucket Cloud does not currently provide a server-side pre-receive API for blocking pushes directly.

Targets

Targets define which artifacts are inspected by a rule.

Target

Description

COMMITS

Validates all commits in the validation scope.

COMMIT

Validates all commits but only one needs to be valid

BRANCH

Validates the source branch name.

TITLE

Validates the pull request title.

DESCRIPTION

Validates the pull request description.

CHANGES

Validates the files a pull request changes; used by approval checks. Use it in a rule of its own; see the warning under approval checks.

Target strategy

The strategy field defines how multiple targets are evaluated.

Strategy

Description

all

All selected targets must satisfy the rule.

one

At least one selected target must satisfy the rule.

Checks

Checks define what is validated when the rule runs.

A rule can contain issue checks, naming checks, approval checks, or a combination of them.

YAML
checks:
  issue:
    ...
  naming:
    ...
  approval:
    ...

Issue checks

Issue checks validate Jira-related requirements, such as issue key presence, issue key consistency, and JQL compliance.

YAML
checks:
  issue:
    key: true
    consistency: true
    jql: "status = 'In Progress'"

Issue key check

The key check validates that issue keys are present and can be resolved in Jira.

Supported forms:

YAML
key: true
key: all
key: one
key:
  enabled: true
  strategy: all

Strategy

Description

all

All detected issue keys in the selected target must be valid Jira issues.

one

At least one detected issue key in the selected target must be a valid Jira issue.

Issue consistency

The consistency check validates that issue keys across the configured targets reference the same Jira issue.

YAML
consistency: true

This is useful when commits, branches, and pull request fields are expected to refer to the same work item.

JQL check

The jql check validates detected Jira issues against a JQL query.

Supported forms:

YAML
jql: "status = 'In Progress'"
jql:
  enabled: true
  query: "status = 'In Progress'"
  strategy: all

Strategy

Description

all

All detected issue references in the selected target must match the configured JQL query.

one

At least one detected issue reference in the selected target must match the configured JQL query.

Naming checks

Naming checks validate branch names, commit messages, pull request titles, and pull request descriptions using regular expressions. See Pattern syntax for the supported syntax; patterns with lookahead, lookbehind, or backreferences are not supported.

YAML
checks:
  naming:
    branch:
      pattern:
        - "^(feature|bugfix|hotfix)/[A-Z]+-\\d+.*"
      strategy: all
    commit:
      pattern:
        - "^[A-Z]+-\\d+.*"
      strategy: all
    pullRequest:
      title:
        pattern:
          - "^[A-Z]+-\\d+.*"
        strategy: all
      description:
        pattern:
          - ".*Closes [A-Z]+-\\d+.*"
        strategy: all

Naming check options

Field

Description

branch

Validates the source branch name.

commit

Validates commit messages.

pullRequest.title

Validates the pull request title.

pullRequest.description

Validates the pull request description.

Each naming option supports either a shorthand string or an expanded object.

Shorthand syntax

YAML
checks:
  naming:
    branch: "(feature|bugfix|hotfix)/[A-Z]+-\\d+.*"

Strategy

Description

all

All configured regex patterns must match.

one

At least one configured regex pattern must match.

Approval checks

Approval checks react when a pull request changes certain files. They need the target CHANGES and the trigger PULL_REQUEST. Each rule has one set of files; for other files, add another rule. A rule can add the selected people as reviewers, require their approval, or both.

YAML
rules:
  - title: "Payment code needs two owner approvals"
    triggers: [PULL_REQUEST]
    target: [CHANGES]
    checks:
      approval:
        files: "^src/payment/"
        users:
          - "557058:00000000-0000-0000-0000-000000000001"
          - "557058:00000000-0000-0000-0000-000000000002"
        requiredApprovals: 2
        addAsReviewers: true
  - title: "Add the technical writer to documentation changes"
    triggers: [PULL_REQUEST]
    target: [CHANGES]
    checks:
      approval:
        files:
          pattern: ["^docs/", "^README\\.md$"]
        users: ["557058:00000000-0000-0000-0000-000000000003"]
        requireApproval: false
        addAsReviewers: true

Approval check options

Field

Description

enabled

Enables the check. Set automatically when files is configured.

files.pattern

Regular expressions matched against the full path of each changed file. The rule applies if at least one changed file matches. A single string is accepted as shorthand: files: "^src/payment/".

users

Atlassian account IDs of the users the rule is about.

addAsReviewers

true adds the users and, with repositoryAdmins, all repository administrators as reviewers when the pull request is created or a later update changes a matching file, so Bitbucket notifies them. Defaults to false.

requireApproval

true blocks the merge until the required approvals are given. Defaults to true.

repositoryAdmins

true selects everyone with admin permission on the repository as well. Defaults to false.

requiredApprovals

Number of approvals needed from users and repository administrators together. Defaults to 1. Without repositoryAdmins, at most the number of users.

At least one of addAsReviewers and requireApproval must be true, and at least one user or repositoryAdmins: true is required. Groups are not supported yet, because Bitbucket Cloud does not currently provide group membership to apps through its supported REST API; support is planned as soon as this becomes possible.

Do not combine CHANGES with other targets and strategy: one. One valid other target is then enough for the rule to pass, and the pull request can be merged without the required approval. Keep approval checks in a rule with target: [CHANGES] only.

Conditions

Conditions define whether a rule should run.

Currently, the preferred CaC format supports pull request, branch, and changed files conditions.

YAML
conditions:
  branch:
    include:
        pattern: ["^feature/.*"]
        strategy: one
  pullRequest:
    destination:
      include:
        pattern: ["^main$", "^release/.*"]
        strategy: one

Pull request condition

The pull request condition can restrict rule execution based on:

  • destination branch

Each branch condition can define include and exclude rules.

YAML
conditions:
  pullRequest:
    destination:
      include:
        pattern: ["^main$", "^release/.*"]
        strategy: one
      excluce:
        pattern: ["^feature/.*", "^bug/.*"]
        strategy: one

Branch condition

Pull request condition can restrict rule execution based on:

  • branch/source-branch

Each branch condition can define include and exclude rules.

YAML
conditions:
  branch:
      include:
       pattern: ["^feature/.*", "^bug/.*"]
        strategy: one
      exclude:
        pattern: ["^main$", "^release/.*"]
        strategy: one

Changed files condition

The changed files condition can restrict rule execution based on:

  • the file paths a pull request changes; for a renamed file, the old and the new path count

It uses the key content and defines include and exclude rules like the branch condition. Use either include or exclude: when include is set, it alone decides whether the rule runs. It applies to pull requests, commits, and pushes; for commits and pushes, the local Git hook sends the changed files.

YAML
conditions:
  content:
    include:
      pattern: ["^src/", "^pom\\.xml$"]
      strategy: one

A single pattern can be written as a string, for example exclude: "\\.md$".

Include and exclude

Condition

Description

include

The rule is executed only if the branch matches the include pattern.

exclude

The rule is skipped if the branch matches the exclude pattern, unless an include condition takes precedence.

Pattern strategy

Strategy

Description

all

All configured patterns must match.

one

At least one configured pattern must match.

For exclude conditions, the default strategy is one.

Example configurations

Jira issue key validation

YAML
rules:
  - title: "Jira issue keys"
    error: "One or more commits lack a valid Jira issue key."
    hint: "Include a valid Jira issue ID like 'ABC-123' in each commit message."
    success: "All commits reference valid Jira issues."
    target: [COMMITS, BRANCH]
    checks:
      issue:
        key: true
        consistency: true

Branch naming convention

YAML
rules:
  - title: "Branch naming"
    error: "Branch name does not follow the required format."
    hint: "Use feature/ABC-123-description"
    target: [BRANCH]
    checks:
      naming:
        branch:
          pattern:
            - "(feature|bugfix|hotfix|release)/[A-Z]+-\\d+.*"
          strategy: all

JQL validation

YAML
rules:
  - title: "Issue status validation"
    error: "Issue is not in a valid review state."
    hint: "Move the Jira issue to 'In Review'."
    success: "The issue is in a valid review state."
    target: [COMMITS, BRANCH, TITLE]
    checks:
      issue:
        jql:
          query: "status in ('In Review', 'Ready for Merge')"
          strategy: all

Feature freeze for release branches

YAML
rules:
  - title: "Feature Freeze"
    error: "This pull request includes a new functionality but targets a release branch."
    hint: "Please target a development branch for the pull request."
    success: "Only allowed issue types are linked to this release pull request."
    triggers: [PULL_REQUEST]
    target: [COMMITS, BRANCH, TITLE, DESCRIPTION]
    strategy: all
    description: "Prevents merging feature-related changes into release branches."
    checks:
      issue:
        jql: "issueType = Bug"
    conditions:
      pullRequest:
        destination:
          include:
            pattern: ["release/.*"]
            strategy: all

Important notes

  • If no configuration file exists, no CaC rules are executed

  • Rule changes become part of the repository history

  • Different branches can use different rule configurations

Key takeaway

Configuration as Code enables versioned, reviewable, and branch-specific compliance configurations directly inside the repository. It allows teams to define triggers, targets, checks, and conditions in YAML while reusing the same validation model that is available in the UI.