问题
I am using Gitlab for our source code management, jenkins for CI jobs and JIRA for issue tracking.
Once I commit in gitlab with an issue number for example "Project-123 edited demo file.", I have a jenkins hook that triggers a build. I have the JENKINS's Jira Plugin and use Progress JIRA issues by workflow action. I have a two part question:
- my JQL for searching for the issue is:
project=PROJ and status="Build Started" and updated >= "-15m"
My workflow action is Jenkins Build is Successful. However, if i have multiple builds running, when the first build completes successfully it will transition both the issues to BUILD SUCCESSFUL no matter how the second build ends. I want a way I can populate $ISSUE_ID using the commit message in jenkins's SCM change for the jira plugin so I can specify the issue to transition. - Progress the worflow a different way if the build fails.
回答1:
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"
来源:https://stackoverflow.com/questions/34144116/how-can-i-get-jira-issue-number-from-a-commit-message-in-jenkins