bitbucket pipelines variables in line
Asked Answered
M

2

7

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 : )

Masera answered 27/10, 2022 at 21:56 Comment(2)
You can define them in the Project/Repo settings, why would you want to define them here?Atul
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 :)Masera
L
11

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
          - ...
Leavening answered 28/10, 2022 at 7:52 Comment(1)
Thank you very much, :) It makes no sense for bitbucket not to have this functionality :)Masera
B
0

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
Bitstock answered 1/5, 2023 at 17:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.