We are migrating from a local Bitbucket server to Bitbucket Cloud. We want to copy our snippets from server to cloud.
Snippets are a third-party add-on in the server product, and a built-in feature in the cloud product.
The current version of Bitbucket Cloud Migration Assistant does not handle snippets.
The first way I thought of is the following:
- Use the Snippets add-on API to copy/clone the snippet to a local PC. (see ETA below)
- Edit the URL in the snippet's Git configuration file, either manually or using the `git remote` command. (I just made this up. It works for repositories, so why not for snippets?)
- Use the BB Cloud API to copy/push/write the snippet to the cloud.
Will that work?
If so, what's the REST API call for pushing to our cloud account?
Is there an easier way?
Has someone already done this -- and if so, how did you do it?
EDITED TO ADD:
The Snippets add-on API can be used to retrieve the contents of one or more snippets on the local server. The contents are retrieved as a JSON object, which must then be parsed to recover the contents of each snippet.
I have not succeeded (yet) at using the BB Cloud API to retrieve or write snippets. However, git commands can be used to pull and push snippets created in BB Cloud.
The second way I thought of is the following:
- Use the Snippets add-on API to copy/clone the snippet to a local PC.
- Use a script or short program to parse the JSON content and create each snippet as its own folder or directory on the local PC.
- Either manually or using the BB Cloud API, create a blank snippet for each snippet in the cloud.
- Use the BB Cloud API or Git commands to push/write the snippet to the cloud.
The problem with this approach is that I lose the authorship and creation dates of the original snippet contents.
Also, this seems like a tedious, excessively manual, and error-prone way to migrate the snippets from our local server to the cloud.
Is there a better way?
ADDITIONAL INFO, TWO DAYS LATER:
It looks like I can use the BB Cloud API to create snippets in our workspace, preserving most of the metadata. (Links here for the snippet itself, here for the comments.) I've written a short Python script to do the work. Now I just need to figure out what an `access_token` is, how to obtain one, and how to specify it in the API request. Unfortunately, I'm more dev than IT oriented, so I'm having some difficulty understanding the Authentication Methods documentation.
I created and am using an app password instead, avoiding the access_token issue completely. API GET requests to both local and cloud servers are working. All that remains is getting the API POST requests working.