【问题标题】:Configuring a bitbucket repository to "activate" pipelines配置 bitbucket 存储库以“激活”管道
【发布时间】:2018-01-17 18:00:13
【问题描述】:

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

【问题讨论】:

    标签: bitbucket-api bitbucket-pipelines


    【解决方案1】:

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

    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
        }'
    

    【讨论】:

    • Bitbucket 似乎更新了他们的其余 API 引用,因此接受的答案不再有效。此答案目前是最新的。
    【解决方案2】:

    您可以使用 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 推送到您创建的存储库。

    curl https://api.bitbucket.org/2.0/repositories/<username>/<slug>/src \
        -F /bitbucket-pipelines.yml=@bitbucket-pipelines.yml
    

    然后为您的项目启用管道

    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"
        }'
    

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

    $ 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>"
        }
      }'
    

    参考资料:

    【讨论】:

    • 将 bitbucket-pipelines.yml 推送到您的源是否启用自动管道?你不需要启用它吗?
    • 我找到了启用管道的请求 curl -X PUT -is -u ':' \ -H 'Content-Type: application/json' \ api.bitbucket.org/2.0/repositories/<name/<project>/… \ - d'{“启用”:真,“类型”:“repository_pipelines_configuration”}'
    • 是的,需要先启用管道插件才能使用管道端点。
    • @Mektoub,您可以使用信息编辑答案以启用管道
    • 这个答案已经过时了。您必须使用 pipelines_config 端点来启用管道,如 Michal Tenenberg 的回答。
    猜你喜欢
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    • 2018-10-24
    • 2019-03-31
    • 2021-07-31
    • 2021-03-23
    • 2017-11-06
    • 1970-01-01
    相关资源
    最近更新 更多