Skip to main content
Example scripts
arrow icon
To homepage
Bitbucket
Data centre icon
Data Center

Find branch by name

Tags
Created 1 year ago, Updated 5 month(s) ago
App in script
ScriptRunner For Bitbucket
ScriptRunner For Bitbucket
by Adaptavist
Compatibility
compatibility bullet
Bitbucket (6.0 - 7.17)
compatibility bullet
ScriptRunner For Bitbucket (7.10.0)
Language |
groovy
import com.atlassian.bitbucket.repository.RefService
import com.atlassian.bitbucket.repository.Repository
import com.atlassian.bitbucket.repository.ResolveRefRequest
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.parameters.annotation.RepositoryPicker
import com.onresolve.scriptrunner.parameters.annotation.ShortTextInput

import static com.atlassian.bitbucket.repository.StandardRefType.BRANCH

@RepositoryPicker(label = "Repository", description = "Enter the repository name")
Repository repository

@ShortTextInput(label = "Branch", description = "Enter the branch name")
String branchName

def refService = ComponentLocator.getComponent(RefService)

refService.resolveRef(new ResolveRefRequest.Builder(repository).with {
    type(BRANCH)
    refId("refs/heads/${branchName}")
}.build())
Having an issue with this script?
Report it here