Using Soy templates to create a BitBucket plugin configuration page

What you are asking is fairly broad, and you haven’t provided many details about your plugin’s setup. So hopefully this information will help, but if not feel free to reply and ask for more specifics.


Your first question was around getting the data from the client to the server.
There are generally 2 ways I’d recommend doing this, but it depends on your front-end setup as to which one is better for you:

  1. HttpServlet (from looking at your code snippet, this is probably the one you want), or
  2. RestResource

The HttpServlet has a doPost method which your servlet can override. A form submission from your soy will call that method with the details of your form and from there you can save your data (we’ll get to that soon).
Documentation
Example (from bitbucket-server-example-plugin)

The RestResource uses javax annotations (e.g. @POST) and you can use javascript to post to this endpoint. Once in the resource, you can read data from the request and save it.
Documentation
Example (from bitbucket-code-coverage-plugin)


Your second question was around storing the data. There are a few ways to do this, and it will depend on what data you are trying to store.

  1. Plugin settings
  2. Active objects

Plugin settings is to store configuration for your plugin. It is not for storing user settings, project settings, repo settings or anything else that is scoped to something more specific than your global plugin settings.
Documentation
Example (from stash-auto-unapprove-plugin)

Active objects allows you to create tables in the database to store your data. While its a little harder to get started with active objects than it is with plugin settings, it is definitely a much better option for the data that most plugins store.
Documentation
Example (from bitbucket-code-coverage-plugin)

Hopefully that was helpful!
I didn’t go into too much details because I’m not sure which option is best for you. Let me know if you’d like me to expand on anything.

Regards,
Kristy

5 Likes