0

I have a bitbucket pipeline where I want to retrieve some part of the branch name (the ticket name)

I basically get the branch name with :

 - BRANCH_NAME="$(git rev-parse --abbrev-ref HEAD)"

Now the branch name is like fix/DOM-123-my-ticket-info

I would like to basically do something like

 - BRANCH_NAME="$(git rev-parse --abbrev-ref HEAD)"
 - TICKET_NAME= // a way to retrieve DOM-123 from $BRANCH_NAME

Do you know how would this be possible ?

I haven"t find anything on how such a thing would be possible.

torek
  • 448,244
  • 59
  • 642
  • 775
Bobby
  • 4,372
  • 8
  • 47
  • 103
  • What are the rules for ticket names? No slashes? Are `DOM` and `my-ticket-info` fixed strings? – phd Oct 24 '22 at 13:41
  • This https://stackoverflow.com/q/69468283/11715259 is your actual question, am I wrong? – N1ngu Oct 24 '22 at 15:54
  • 1
    probably fine yeah thank you ! ticket name is always after first / and end always after second - – Bobby Oct 25 '22 at 01:26

1 Answers1

1

If you want to run a regular expression outside your usual language/runtime, you should get used to the grep utility.

A naive approach for your case:

TICKET_NAME=$(echo $BRANCH_NAME | grep --only-matching --extended-regexp 'DOM-[0-9]+')

(you might need to workout the actual ticket name regex)


Friendly reminder: the branch name is accessible in the $BITBUCKET_BRANCH environment variable (for branch pipelines, no custom nor tag-triggered pipelines)

N1ngu
  • 2,862
  • 17
  • 35