我的客户之一正在运行v5.14.0 (不是Bitbucket Cloud!)实例。在他们的内联网里。我尝试使用REST来获取项目列表,对于我正在处理的项目,获取一个git存储库列表:
# first REST API call: returns list of projects on server,
# `?limit=1000` appended to work around / disable pagination:
# https://docs.atlassian.com/bitbucket-server/ ...
# ... rest/5.14.0/bitbucket-rest.html#idm46783597898304
curl --header "Authorization: Bearer <my access token>" \
https://<bitbucket hostname>/rest/api/1.0/projects?limit=1000
# second REST API call: returns list of repos in <project ID>
# https://docs.atlassian.com/bitbucket-server/ ...
# ... rest/5.14.0/bitbucket-rest.html#idm45701776945568
curl --header "Authorization: Bearer <my access token>" \
https://<bitbucket hostname>/rest/api/1.0/projects/<project key>/repos?limit=1000总的来说,这是很好的。但是,问题是第二个调用只返回具有公共可见性的存储库,虽然我能够在登录后看到web应用程序中的公共和私有repos,但似乎没有任何方法可以使用REST获取私有存储库。
我也试过
# alternate approach: list repo by name
# https://docs.atlassian.com/bitbucket-server/ ...
# ... rest/5.14.0/bitbucket-rest.html#idm46783597782384
curl --header "Authorization: Bearer <my access token>" \
https://<bitbucket hostname>/rest/api/1.0/repos?name=<name of private repo>但这也不返回存储库信息。
我已经彻底搜索了文档,但到目前为止,这似乎只是Bitbucket中的一个bug,通过REST获得私有存储库是不可能的。
Q:,有没有人能让它工作?
Q:是否有人使用Bit斗ServerRESTAPI?你的经历/印象如何?
发布于 2018-10-23 17:57:53
它可能与用户拥有的权限有关。是管理员用户吗?
我使用了这个脚本来获得所有的回复:
#!/usr/bin/python
import stashy
import os
import sys
import urllib2
import json
import base64
bitbucketBaseUrl = "https://bitbucket.company.com"
bitbucketUserName = "admin"
def validateScriptParameters():
if len(sys.argv) != 2:
sys.exit("Usage: {} [Bit Bucket admin password]".format(
os.path.basename(sys.argv[0])))
validateScriptParameters
bitbucketPassword = sys.argv[1].strip()
bitbucket = stashy.connect(bitbucketBaseUrl, bitbucketUserName, bitbucketPassword)
projectList = bitbucket.projects.list()
total = 0
for project in projectList:
projectName = project['key']
repoList = bitbucket.projects[projectName].repos.list()
for repo in repoList:
print repo['name']这个脚本是以管理员用户的身份运行的,您需要stashy:
pip install stashy我发现REST非常好,想知道如何提出正确的请求可能有点棘手,但是文档已经存在了。不过很难找到。每个版本都会发布新的文档,而且它们往往是最好的:
还有一个用于bitbucket的REST插件,它允许您直接针对服务器测试请求:

发布于 2022-08-10 00:18:19
也有同样的问题。基本资产不退还私人项目。我不得不使用OAuth,现在它获取私有存储库。我遵循了这些指令。
https://stackoverflow.com/questions/52666503
复制相似问题