I have a branch name in the form of:
origin/release/JIRA-1000-some-issue-name
I want to write a Batch script to extract only the Jira issue ID as such:
JIRA-1000
So that I could use the ID in a commit message further on.
Could someone please suggest a solution!
With the help of Suggestions in the Comments, I was able to arrive at a solution.
The Batch Script has the following steps:
branch_name
lastPart
lastPart
to extract Jira ID with delimiters /-git rev-parse --abbrev-ref HEAD > %temp%\git.txt
for /f "Tokens=*" %%a in (%temp%\git.txt) do @set branch_name=%%a
for %%a in ("%branch_name%\.") do set "lastPart=%%~nxa"
for /f "tokens=1,2 delims=/-" %%G in ("%lastPart%\.") do @set jiraid=%%G-%%H
echo %branch_name%
echo %lastPart%
echo %jiraid%
The output should be:
origin/release/JIRA-1000-some-issue-name
JIRA-1000-some-issue-name
JIRA-1000
Then the variable jiraid
can be used further.