You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Windows批处理脚本从Git分支名提取Jira问题ID

Windows批处理提取Jira问题ID解决方案

方法说明

针对格式为origin/release/JIRA-1000-some-issue-name的分支名,可通过两次for /f命令分割字符串,精准提取JIRA-XXXX格式的问题ID:

批处理脚本示例

@echo off
setlocal enabledelayedexpansion

:: 替换为实际分支名,也可从命令行参数传入
set "branch_name=origin/release/JIRA-1000-some-issue-name"

:: 第一步:按斜杠分割,提取第三个分段(即JIRA-1000-some-issue-name)
for /f "tokens=3 delims=/" %%a in ("%branch_name%") do set "issue_segment=%%a"

:: 第二步:按横杠分割,提取前两个分段并拼接成Jira ID
for /f "tokens=1,2 delims=-" %%b in ("%issue_segment%") do set "jira_id=%%b-%%c"

:: 输出结果
echo 提取到的Jira问题ID:!jira_id!

endlocal

灵活用法

如果需要从命令行传入分支名,可修改脚本为:

@echo off
setlocal enabledelayedexpansion

set "branch_name=%~1"

if not defined branch_name (
    echo 请传入分支名作为参数,示例:%0 origin/release/JIRA-1000-some-issue-name
    exit /b 1
)

for /f "tokens=3 delims=/" %%a in ("%branch_name%") do set "issue_segment=%%a"
for /f "tokens=1,2 delims=-" %%b in ("%issue_segment%") do set "jira_id=%%b-%%c"

echo 提取到的Jira问题ID:!jira_id!

endlocal

运行时直接执行:extract_jira_id.bat origin/release/JIRA-1000-some-issue-name

内容的提问来源于stack exchange,提问作者kartiks77

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 06:31:02