diff --git a/build.gradle b/build.gradle index fd98fd53c..2e81a4d83 100644 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,7 @@ dependencies { implementation 'org.jenkins-ci.plugins.workflow:workflow-api:2.28' implementation 'org.jenkins-ci.plugins:branch-api:2.0.20' implementation 'org.jenkins-ci.plugins:scm-api:2.2.7' + implementation 'org.jenkins-ci.plugins:cloudbees-bitbucket-branch-source:2.4.1' implementation 'org.jenkins-ci.plugins:junit:1.24' implementation 'org.jenkins-ci.plugins:script-security:1.76' implementation 'org.jenkinsci.plugins:pipeline-model-definition:1.8.4' // version declarative started supporting JTE diff --git a/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemWrapperFactory.groovy b/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemWrapperFactory.groovy index 01c703253..e580a137c 100644 --- a/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemWrapperFactory.groovy +++ b/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemWrapperFactory.groovy @@ -23,6 +23,8 @@ import jenkins.scm.api.SCMFileSystem import jenkins.scm.api.SCMHead import jenkins.scm.api.SCMRevision import jenkins.scm.api.SCMSource +import com.cloudbees.jenkins.plugins.bitbucket.BranchSCMHead +import com.cloudbees.jenkins.plugins.bitbucket.PullRequestSCMHead import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition import org.jenkinsci.plugins.workflow.flow.FlowDefinition import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner @@ -99,7 +101,14 @@ class FileSystemWrapperFactory { SCMFileSystem fs String scmKey - if (tip) { + if (head instanceof PullRequestSCMHead) { + // For BitBucket pull requests, we must use BranchSCMHead instead of PullRequestSCMHead + // to retrieve the SCMFileSystem from the source branch + BranchSCMHead branchHead = new BranchSCMHead(head.getBranchName()) + SCMRevision sourceRevision = scmSource.fetch(branchHead, listener) + scmKey = branch.getScm().getKey() + fs = SCMFileSystem.of(scmSource, branchHead, sourceRevision) + } else if (tip) { scmKey = branch.getScm().getKey() SCMRevision rev = scmSource.getTrustedRevision(tip, listener) fs = SCMFileSystem.of(scmSource, head, rev)