regex - bash expression to get the jira key out of git commit -
i have below code in jenkins configuration in execute shell
jira_key=$(curl --request "http://jenkins-server/job/myproject/job/mysubproject/job/mycomponent/${build_number}/api/xml?xpath=/*/changeset/item/comment" | sed -e "s/<comment>\(.*\)<\/comment>/\1/")
the result of above command is
jira_key=<comment>jra-1011 commit message. </comment>
i not sure how can improve above expression start , end tags excluded result.
however ultimate goal extract jira key first word in comment i.e. jra-1011 , store in jira_key. once tags excluded can first word command
set -- $jira_key jira_key=$1
is there other better way this?
the xml
<freestylebuild _class="hudson.model.freestylebuild"> <changeset _class="hudson.plugins.git.gitchangesetlist"> <item _class="hudson.plugins.git.gitchangeset"> <comment> jra-1011 commit message. </comment> </item> </changeset> </freestylebuild>
Comments
Post a Comment