opendevstack / ods-jenkins-shared-library

Shared Jenkins library which all ODS projects & components use - provisioning, SonarQube code scanning, Nexus publishing, OpenShift template based deployments and repository orchestration
Apache License 2.0
72 stars 57 forks source link

GitService.issueIdFromCommit failing when Issue ID is not on the first line in a multiline commit message #974

Open mariussl opened 1 year ago

mariussl commented 1 year ago

Describe the bug Some time (around 6 weeks) ago bitbucket changed the content of the automatically generated merge commit message for pull requests. My bitbucket version is now 7.21.7 .

Before:

Pull request #43: Feature/MYPROJECT-147 jenkins pipeline broken

Merge in MYPROJECT/myrepo from feature/MYPROJECT-147-jenkins-pipeline-broken to master

* commit 'b5b627a315fa9e739d81d7c38d937676d44795d7':

Now:

Pull request #49: adapt to new url

Merge in MYPROJECT/myrepo from bugfix/MYPROJECT-483-url-is-defect

* commit '0749118969654c44f400f6a3034ae3bd5bb48969':

Since this change the context.issueId in my Jenkinsfile inside the odsComponentPipeline is always empty when a pull request for a feature/bugfix branch is merged back to master.

I believe the problem is in GitService.groovy Line 44ff : The msgMatcher does not carry the multiline flag to also check subsequent lines for an issue id.

Changing the code as follows should fix the bug:

def msgMatcher = commitMessage =~ /(?m)${uppercaseProject}-([0-9]+)/

To Reproduce Steps to reproduce the behavior:

  1. Create a bugfix/feature branch
  2. Change something
  3. Create a pull request
  4. Edit Jenkinsfile to output context.issueId
  5. Merge pull request with a multiline commit message that has the PROJECTID-ISSUED not on the first line (as Bitbucket 7.21.7 does it automatically)
  6. Observe output of context.issueId to be empty

Expected behavior When merging a pull request with PROJECTID-ISSUEID somewhere in a multiline commit message context.issueId should be set accordingly.

Affected version (please complete the following information):

Gradle code to test regex Remove the (?m) flag in the matcher and the regex fails.

def s = """
Pull request #50: remove

Merge in ODMC/odmc-fullstack from bugfix/MYPROJECT-484-test-pull-request-message to master

* commit '99dee286861205fcf0d5ad787ce53c69c77770bf':
  remove
"""

def msgMatcher = s=~ /(?m)MYPROJECT-([0-9]+)/

if (msgMatcher) {
   println("yes")
   println(msgMatcher[0][1])
} else {
   println("no")
}
​