How can I get JIRA issue number from a commit message in Jenkins

北城以北 提交于 2019-12-02 07:44:11

I ended up using a work around. Here is how I solved each: 1- I wrote a shell script that took the changes by requesting the api for the build. Then I wrote a regex to take out the issue key from the commit message. I took out only the first reference of an issue. The I used the envinject plugin in jenkins to inject the issue id as a build property to be used later on by the JIRA plugin's progress issue by workflow action step. Here is the shell script.

xmlfile=$(curl -s "http://*********:8080/jenkins/job/***/${BUILD_NUMBER}/api/xml?wrapper=changes&xpath=//changeSet//comment")
re="PRJ-([0-9])*"
if [[ $xmlfile =~ $re ]];
  then issueKey=${BASH_REMATCH[0]}
fi
re2="([0-9])+"
if [[ $issueKey =~ $re2 ]];
  then echo ISSUE_ID=${BASH_REMATCH[0]} > env.properties
fi

in the jira pugin I used issueKey=PRJ-$ISSUE_ID as my jql with the status.

2- For this part, I used the TriggerParametrizedBuild plugin and started a build if the current build failed or was unstable. This new build only progressed the workflow back to "In Progress"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!