There is som eenvironment variable to access step name in pipelines

Garry Dias July 9, 2020

Hi

 

Problem's short version

 

I'd like to access the step name in my script section from a envrionment variable. There are some built in variables?

For example,

When the step below runs...

(...)

  - step: 
    name: my_cool_name
script:
- echo $STEP_NAME

... then the output should be:

my_cool_name

 

Real problem

 

I have dozens of steps running a shell script (sh). Inside this sh file I need access the step's name in order to generate some reports. My current solution is that:

(...)

  - step: 
    name: my_cool_name1
script:
- export STEP_NAME=my_cool_name1
- ./report.sh
(...)
  - step: 
    name: my_cool_name50
script:
- export STEP_NAME=my_cool_name50
- ./report.sh

 

I'd like to remove the first script line, so I'll be able to write a default step with an anchor name and then, in branches section, do something like that:

 

pipelines:
default:
- step: &defaultStep
name: none
script:
- ./report.sh

branches:
'dev':
     - step: 
  <<: *defaultStep
      name: my_cool_name1
       - step: 
     <<: *defaultStep
          name: my_cool_name2
     (...)
       - step: 
     <<: *defaultStep
         name: my_cool_name50

 

Thanks

 

1 answer

1 vote
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 18, 2024

Hi @Garry Dias,

I understand that you're looking for a way to get the specific step name in Pipelines via the environment variable.
Unfortunately, there's no default variable for getting the specific step name.

We do have an existing feature request for it that can be located through this link. - https://jira.atlassian.com/browse/BCLOUD-23102
In the meantime, please feel free to upvote and watch the existing feature request through the provided link so that you'll be notified of any updates on its progress.
We appreciate your patience and understanding as we continue to improve Bitbucket Cloud according to our policy on implementing new features.

As a workaround, you can get the current step name using an API endpoint and save it as an environment variable.
Here's an example of YAML configuration:

image: atlassian/default-image:4

pipelines:
  default:
      - step:
          name: "Some Step Name"
          script:
            - BB_STEP_NAME=$(curl --request GET --url "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_FULL_NAME}/pipelines/%7B${BITBUCKET_PIPELINE_UUID}%7D/steps/%7B${BITBUCKET_STEP_UUID}%7D?fields=name" -u $BITBUCKET_USERNAME:$BITBUCKET_APP_PASSWORD | jq -r '.name')
            - echo $BB_STEP_NAME

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events