jenkinsci / bitbucket-push-and-pull-request-plugin

Plugin for Jenkins v2.138.2 or later, that triggers job builds on Bitbucket's push and pull request events.
https://plugins.jenkins.io/bitbucket-push-and-pull-request
MIT License
46 stars 50 forks source link

Can not checkout merge commit in Jenkins Pipeline #322

Open kirilla111 opened 5 months ago

kirilla111 commented 5 months ago

Hi,

Our team uses BB-server and pipeline configured to build on PR merge in master

Problem occurs when we use merge strategy "Merge commit --no-ff". Bitbucket sends:

{
  "eventKey": "pr:merged",
  "pullRequest": {
    "fromRef": {
      "id": "refs/heads/<branch>",
      "displayId": "test3",
      "latestCommit": "326eabb767f9bd19dfb510a81284142adad595a5",
    },
    "toRef": {
      "id": "refs/heads/master",
      "displayId": "master",
      "latestCommit": "43cd3eac23c2ad23fbe0586ad3e22259f15a841c",
    },
    "properties": {
      "mergeCommit": {
        "displayId": "8dc7e904f5d",
        "id": "144311b20df08572b13c3b4e20c72796e70e6d5c"
      }
    }
  }
}

So, we expect build under hash of commit merged in master: 144311b20df08572b13c3b4e20c72796e70e6d5c

But in facts scm step checkout commit from fromRef.lastestCommit (326eabb767f9bd19dfb510a81284142adad595a5)

And env.BITBUCKET_PAYLOAD has no information about properties.mergeCommit (144311b20df08572b13c3b4e20c72796e70e6d5c). So, we can`t checkout expected commit via git command.

Our Jenkins file (if needed):

properties([
        pipelineTriggers([
                bitBucketTrigger(
                        credentialsId: '<creds>',
                        triggers: [
                                [
                                        $class      : 'BitBucketPPRPullRequestServerTriggerFilter',
                                        actionFilter: [
                                                $class         : 'BitBucketPPRPullRequestServerMergedActionFilter',
                                                allowedBranches: 'master',
                                        ]
                                ]
                        ]
                )
        ])
])
pipeline {
    ...
     stages {
     ...
         stage("scm step") {
                steps {
                    dir("<dir>") {
                        script {
                            checkout scm: [
                                    $class           : 'GitSCM',
                                    branches         : [[name: "master"]],
                                    browser          : bitbucketServer("<url>"),
                                    userRemoteConfigs: [
                                            [
                                                    credentialsId: '<creds>',
                                                    url          : "<url>"
                                            ]
                                    ]
                            ]
                        }
                    }
                }
            }
    }
    ...
}

I`m tried different combinations of trigger and scm step configuration but result is always the same. Can you help?

Joakolguin commented 2 months ago

Same issue here, with BB-Cloud. Bitbucket payload has the Merge commit information, but the jenkins plugins doesn't capture that value.

Regards.