首页 文章

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

提问于
浏览
1

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

2 回答

  • 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
    

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

    参考文献:

  • 2

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

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

相关问题