2

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?

1 Answer 1

3

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
1
  • 1
    I'm sorry, but the question was specifically if variables can be used as input for DEPLOYMENT variable, the answer has also been confirmed as NO by Atlassian. Your example doesn't solve my use case. As it stands right now, the answer is that you cannot use variables for the deployment key.
    – kravb
    Commented Oct 27, 2021 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.