Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use variable for Bitbucket custom pipeline deployment value

I am trying to set the deployment variable for a step using a variable that is passed to a custom pipeline. The idea is not to have to duplicate the custom pipeline as the only change is the deployment variables that are read from bitbucket settings.

The definition looks as follows, but throws an error

pipelines:
  custom:
    my-pipeline:
       - variables:   
          - name: deployment
       - step: 
           deployment: $deployment 
           script:
             - ...

Am I missing something here, or is the deployment key not allows to accept a variable?

like image 439
kravb Avatar asked Sep 08 '25 06:09

kravb


1 Answers

Unfortunetly you can't use variables in the deployment field. Variables are only available in script fiels. However, your problem is easily solved in another way: anchors

For example:

definitions:
  steps:
    - step: &Test-step
        name: Run tests
        script:
          - npm install
          - npm run test
    - step: &Deploy-step
        name: Deploy to staging
        script:
          - npm install
          - npm run build
          - fab deploy
pipelines:
  default:
    - step: *Test-step
    - step:
        <<: *Deploy-step
        name: Deploy to Staging
        deployment: staging
        trigger: manual
  custom:
    Staging Deployment
      - step: *Test-step
      - step:
          <<: *Deploy-step
          deployment: staging
    Production Deployment
      - step: *Test-step
      - step:
          <<: *Deploy-step
          deployment: production
like image 54
Stanislau Listratsenka Avatar answered Sep 11 '25 01:09

Stanislau Listratsenka