6

It is possible to declare variables inside the pipeline file, as in this GitHub example:

# ...

env:
  NODE_VERSION: 16.3.1
  FOLDER_PATH: Project


# ...

    steps:
      - name: Move to project folder
        run: cd $FOLDER_PATH

# ...

Is it possible to do something similar in the bitbucket pipeline files? (How?)

Thanks any help : )

Flavio Silva
  • 95
  • 1
  • 8
  • You can define them in the Project/Repo settings, why would you want to define them here? – Randommm Oct 28 '22 at 06:03
  • 1
    Because I don't want to have to set the same variables every time I create a new project, so I was left with a "template" pipeline file :) And because I think it becomes more explicit :) – Flavio Silva Oct 28 '22 at 10:03

2 Answers2

10

No.

There is a feature request for that https://jira.atlassian.com/browse/BCLOUD-17453 .

Still "gathering interest" though.

The nearest approximation is to write a YAML anchor that exports those vars and use it in every step.

definitions:
  yaml-anchors:
    - &setenv-script >-
        export NODE_VERSION=16.3.1
        && export FOLDER_PATH=Project

pipelines:
  default:
    - step:
        script:
          - *setenv-script
          - ...
    - step:
        script:
          - *setenv-script
          - ...
N1ngu
  • 2,862
  • 17
  • 35
-1

I know this question is a little old. But, I ran across it while looking for a solution myself. I did find that Bitbucket has a feature, that fit my needs, and matches this question (I think) in this post, Adding human interaction back into automated builds

For my use case, I wanted an ability to run shell commands through a custom pipeline to do minor troubleshooting. For example, an "ifconfig" or a "nslookup". Rather simple troubleshooting steps, but within the scope of my container. An example of how I am using this in my code is like this:

pipelines:

  default:
  ...

  custom:

  Troubleshooting:
  - variables:
    - name: COMMAND
  - step: 
    name: Custom Troubleshooting Commands
    image: *image
    runs-on: *runs-on
    deployment: dev
    script:
    - $COMMAND
DevMan
  • 1