Configuring a bitbucket repository to “activate” pipelines

和自甴很熟 提交于 2019-12-11 09:14:43

问题


I have multiple repositories in a BitBucket project. I wish to automatically create a bitbucket repository, and enable pipelines (setting the pipeline configuration should be easy, with pushing a bitbucket-pipelines.yml file). How can I do it using the REST API?


回答1:


You can create a repository with the 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>

Push your bitbucket-pipelines.yml to your created repo.

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

Then enable pipeline for your project

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

Finally, you can trigger a pipeline for the branch like so.

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

References:

  • Repository API
  • Pipelines API



回答2:


The other answer's "enable pipelines" request did not work for me. This is what worked:

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


来源:https://stackoverflow.com/questions/44871011/configuring-a-bitbucket-repository-to-activate-pipelines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!