【发布时间】:2017-07-26 08:45:07
【问题描述】:
我的 jenkins 作业配置中的以下行执行 shell 检索 jira 密钥
JIRA_KEY=$(curl --request GET "http://jenkins-server/job/myProject/job/mySubProject/job/myComponent/${BUILD_NUMBER}/api/xml?xpath=/*/changeSet/item/comment" | sed -e "s/<comment>\(.*\)<\/comment>/\1/")
JIRA_KEY=$(echo $JIRA_KEY | cut -c10-17)
但如果文本不以 jira 键开头,那么根据当前逻辑,它将分配 10-17 范围内的任何文本。当 <comment> 中不存在 jira 键时,我需要在变量 JIRA_KEY 中存储空字符串“”,我们该怎么做?
这里是xml
<freeStyleBuild _class="hudson.model.FreeStyleBuild">
<changeSet _class="hudson.plugins.git.GitChangeSetList">
<item _class="hudson.plugins.git.GitChangeSet">
<comment>
JRA-1011 This is commit
message.
</comment>
</item>
</changeSet>
</freeStyleBuild>
【问题讨论】:
-
不清楚,您能否告诉我们预期的输出是什么,我看到您正在尝试获取 10 到 17 的字符,请添加更多信息以在代码标签中发布。
-
正如帖子中提到的“当
<comment>中不存在jira键时,我需要在变量JIRA_KEY中存储空字符串”