Introducing default values for custom pipeline variables

Support for including default values in custom pipelines has been a highly requested feature. We are happy to announce that this feature is now live.

Providing a default value helps avoid errors when you manually trigger a custom pipeline. If you often rely on the same value for certain variables, it can be frustrating to get a failed build when you forget to specify the value or have a typo when providing the value. Having a pre-populated default value makes it convenient so you don’t have to type in the same value each time. Additionally, it can help other developers better understand the expected value for a variable.

Here is an example of a pipeline configuration showing how to assign ap-southeast-2 as the default region for this build.

pipelines:
  custom:
    custom-name-and-region:
      - variables:
          - name: Username
          - name: Region
            default: ap-southeast-2  # optionally provide a default value
      - step: 
          script:
            - echo "User name is $Username"
            - echo "and they are in $Region"

When the pipeline is triggered, the user will be prompted to enter their username but the region value is pre-populated to be ap-southeast-2

Default variable values will also be used when you create a pipeline via API and value for a variable is not provide

In this example, variable Username will have the provided value John. Variable Region is not provided so it will have the default value ap-southeast-2.

curl -X POST -is -u username:password \
  -H 'Content-Type: application/json' \
 https://api.bitbucket.org/2.0/repositories/my-workspace/my-repo/pipelines/ \
  -d '
  {
    "target": {
      "ref_type": "branch",
      "type": "pipeline_ref_target",
      "ref_name": "master"
    },
    "variables": [
      {
        "key": "Username",
        "value": "John"
      }
    ]
  }'

When a custom pipeline is scheduled for execution, a default variable value will always be used if declared in the pipeline configuration. Otherwise, an empty string will be used as a value.

Additional documentation on using variables in custom pipelines can be found here. We hope you and your team find this extra flexibility helpful! 

Happy coding!