I want to show all the branch names dynamically using a groovy script by making an api call to bitbucket private repo. I am following this article link.In this article top is using https , instead I like to use ssh.
String baseUrl = "https://bitbucket.org/api"
String version = "1.0"
String organization = "i4niac"
String repository = "mirepoix"
String branchesUrl = [baseUrl, version, "repositories", organization, repository, "branches"].join("/")
String username = "i4niac"
String password = "mypassword"
// Create authorization header using Base64 encoding
String userpass = username + ":" + password;
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
// Create URL
URL url = branchesUrl.toURL()
// Open connection
URLConnection connection = url.openConnection()
// Set authorization header
connection.setRequestProperty ("Authorization", basicAuth)
// Open input stream
InputStream inputStream = connection.getInputStream()
// Get JSON output
def branchesJson = new groovy.json.JsonSlurper().parseText(inputStream.text)
// Close the stream
inputStream.close()