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

前端 未结 1 385
南笙
南笙 2021-01-23 15:36

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-12

相关标签:
1条回答
  • 2021-01-23 16: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"

    0 讨论(0)
提交回复
热议问题