API to create Bitbucket Cloud Pipeline Deployment Environment.
Summary
The purpose of this KB article is to provide instructions on how to use API to create new deployment environment for Bitbucket Cloud Pipeline.
Environment
Bitbucket Cloud
Solution
We are going to use endpoint : https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/environments
curl --request POST \
--url 'https://api.bitbucket.org/2.0/repositories/<WorkspaceSlug>/<RepoSlug>/environments/' \
-u <atlassian_account_email>:<api_token> \
--header 'Content-Type: application/json' \
--data '{
"environment_type": { "name" : "envType"},
"name": "<envName"
}'
In the above API kindly replace the following with correct values.
- <WorkspaceSlug> : ID of the workspace ,please refer to workspace settings to get the workspace ID;
- <repoSlug> : slug of the repository.
- <atlassian_account_email>:<api_token> : Atlassian account email/API token: The authentication can be done via your Atlassian account email and API token (as the example above shows), or using OAuth.
- envType : type of environment - TEST , STAGING , PRODUCTION.
- envName : custom name for your environment.
If you are encountering issues following this documentation, or have any other related questions - please raise a support ticket or raise a community support ticket for further assistance.