我在BitBucket项目中有多个存储库 . 我希望自动创建一个bitbucket存储库,并启用管道(设置管道配置应该很容易,推送一个bitbucket-pipelines.yml文件) . 如何使用REST API执行此操作?
您可以使用BitBucket REST API创建存储库 .
$ curl -X POST -H "Content-Type: application/json" -d '{ "scm": "git", "project": { "key": "Foo" } }' https://api.bitbucket.org/2.0/repositories/<username>/<repo_slug>
将 bitbucket-pipelines.yml 推送到您创建的仓库 .
bitbucket-pipelines.yml
curl https://api.bitbucket.org/2.0/repositories/<username>/<slug>/src \ -F /bitbucket-pipelines.yml=@bitbucket-pipelines.yml
然后 enable 管道为您的项目
curl -X PUT -is -u '<username>:<password>' -H 'Content-Type: application/json' \ https://api.bitbucket.org/2.0/repositories/<username>/<repo_slug> \ -d '{ "enabled": true, "type": "repository_pipelines_configuration" }'
最后,你可以像这样分支 trigger a pipeline .
$ curl -X POST -is -u <username>:<password> \ -H 'Content-Type: application/json' \ https://api.bitbucket.org/2.0/repositories/<username>/<slug>/pipelines/ \ -d ' { "target": { "ref_type": "branch", "type": "pipeline_ref_target", "ref_name": "<branch_name>" } }'
Repository API
Pipelines API
另一个答案的“启用管道”请求对我不起作用 . 这是有效的:
curl -X PUT -is -u '<username>:<password>' -H 'Content-Type: application/json' \ https://api.bitbucket.org/2.0/repositories/<username>/<slug>/pipelines_config \ -d '{ "enabled": true }'
2 回答
您可以使用BitBucket REST API创建存储库 .
将
bitbucket-pipelines.yml
推送到您创建的仓库 .然后 enable 管道为您的项目
最后,你可以像这样分支 trigger a pipeline .
参考文献:
Repository API
Pipelines API
另一个答案的“启用管道”请求对我不起作用 . 这是有效的: