配置 bitbucket 存储库以“激活”管道

ori*_*erg 1 bitbucket-api bitbucket-pipelines

我在 BitBucket 项目中有多个存储库。我希望自动创建一个 bitbucket 存储库,并启用管道(设置管道配置应该很容易,推送一个 bitbucket-pipelines.yml 文件)。我如何使用 REST API 做到这一点?

Mic*_*erg 8

另一个答案的“启用管道”请求对我不起作用。这是有效的:

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
    }'
Run Code Online (Sandbox Code Playgroud)


Olu*_*ule 5

您可以使用 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>
Run Code Online (Sandbox Code Playgroud)

将您的推bitbucket-pipelines.yml送到您创建的存储库。

curl https://api.bitbucket.org/2.0/repositories/<username>/<slug>/src \
    -F /bitbucket-pipelines.yml=@bitbucket-pipelines.yml
Run Code Online (Sandbox Code Playgroud)

然后为您的项目启用管道

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"
    }'
Run Code Online (Sandbox Code Playgroud)

最后,您可以像这样触发分支的管道。

$ 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>"
    }
  }'
Run Code Online (Sandbox Code Playgroud)

参考:

  • 这个答案已经过时了。您必须使用 pipelines_config 端点来启用管道,如 Michal Tenenberg 的回答所示。 (4认同)