ori silberberg
ori silberberg

Reputation: 91

Configuring a bitbucket repository to "activate" pipelines

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?

Upvotes: 2

Views: 2078

Answers (2)

Michal Tenenberg
Michal Tenenberg

Reputation: 518

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

Upvotes: 9

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38982

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 /[email protected]

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:

Upvotes: 5

Related Questions