0

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()
user17970
  • 495
  • 1
  • 9
  • 25
  • What do you mean by "private Bitbucket repository"? If it's really private, that would mean the public should not have read/write access to it. – alex Jan 24 '20 at 20:20
  • public GitHub would not allow me to write to your repo and vice versa , unless it is via PR – user17970 Jan 24 '20 at 22:24

1 Answers1

0

Refer this

As per Bitbucket API documentation -

To use a REST API, your application will make an HTTP or HTTPS request and parse the response so I highly doubt if you can use ssh URL

Pankaj Saini
  • 1,493
  • 8
  • 13