Search code examples
bitbucketbitbucket-apibitbucket-cloud

Download a file from bitbucket feature branch using BitBucketAPI


HI I am trying to download a file based on the bit bucket branch selection . I am able to download the file from ci or master branch , but unable to download from feature branch. Can you please help me .

If i download from CI branch it works : https://api.bitbucket.org/2.0/repositories/***Dev/testrepo/src/ci/pom.xml - this works without any issues

https://api.bitbucket.org/2.0/repositories/***Dev/testrepo/src/feature/testFeature/pom.xml - this is not working and getting java.io.FileNotFoundException:

Could you guys please help me. Thanks in Advance.


Solution

  • the above solution works only to read a file from master and ci branch ( where branch name is not having any slashes in it ) , it will not work for feature/Release branches .

    I am doing it by fetching the last commit hash and with the commit hash and reading the file with last commit hash

    https://api.bitbucket.org/2.0/repositories/domainname/repositoryName/refs/branches/branchName

    From the Json read the commit hash - responseJsonMap["target"]["hash"]

    Then construct the URL with commit hash and read the file https://api.bitbucket.org/2.0/repositories/domainName/repositoryName/src/${hashValue}/pom.xml?at=branchName