How to pass parameters to my client-web-panel plugin? Edited

I'm creating a plugin to decorate the commit overview page. The decorations will be links to an external Web app. The URLs will vary depending on the environment in which the plugin is running, e.g. dev, val, prd. So each Bitbucket server instance should be configurable to pass the correct URL to the plugin for the encvironment in which it runs.

Based on this, I think I need a server-side .properties file in the home dir, a server-side ContextProvider in Java calling ApplicationPropertiesService.getPluginProperty and returning the result in its getContextMap method, and a client-context-provider on the client side. But it's not working for me: Spring throws an NPE at the first reference to the local (@Inject-ed) ApplicationPropertiesService.

I realize the abovementioned article is about hooks, while I'm doing a plugin, and they're different. Maybe there is no ApplicationPropertiesService in the Spring context when processing a plugin?

Is there a canonical way to pass an environment-specific value to client-side plugin code?


<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${}" plugins-version="3">
        <vendor name="${}" url="${project.organization.url}" />

    <!-- add our i18n resource -->
    <resource type="i18n" name="i18n" location="v1-for-bitbucket-plugin"/>

    <client-resource key="commit-comment-overview-resources" name="Commit Overview Resources">
        <directory location="/css/" />
        <directory location="/js/" />
        <directory location="/soy/" />

    <client-web-panel key="commit-comment-create-story-id" location="bitbucket.commit.related-entities">
     <context-provider class="gov.ssa.mde.v1_4_bb_plugin.PluginContextProvider"/>
        <resource name="view" type="soy"
   location="gov.ssa.mde.v1-4-bb-plugin.versionone-for-bitbucket-plugin:commit-comment-overview-resources/com.bitbucket.commitcommentstory.commitForm" />


(NPE thrown at line 41)

package gov.ssa.mde.v1_4_bb_plugin;

import java.util.Map;

import javax.inject.Inject;

import com.atlassian.bitbucket.server.ApplicationPropertiesService;
import com.atlassian.plugin.PluginParseException;
import com.atlassian.plugin.web.ContextProvider;

public class PluginContextProvider implements ContextProvider {

  public ApplicationPropertiesService appPropsSvc;
 public ApplicationPropertiesService getAppPropsSvc() {
  return appPropsSvc;

 public void setAppPropsSvc(ApplicationPropertiesService appPropsSvc) {
  this.appPropsSvc = appPropsSvc;

 private String baseUrlKey = "plugin.v1_4_bb_plugin.v1_base_url";
 private String missingUrlVal = "V1_base_url_missing!";
 private String baseUrl = null;
 private ImmutableMap<String, Object> newContext = null;
 public PluginContextProvider() {

 public Map<String, Object> getContextMap(Map<String, Object> arg0) {
  System.out.println(this.getClass().getName() + ".getContextMap invoked.");

  // Seems BB isn't calling the init method, so I'm placing its code here til I figure out the problem.
  this.baseUrl = appPropsSvc.getPluginProperty(baseUrlKey, missingUrlVal);
  System.out.println(this.getClass().getName() + ".getContextMap got base url:" + this.baseUrl + ".");
  this.newContext = ImmutableMap.<String, Object>builder()
                   .put(baseUrlKey, this.baseUrl)
  System.out.println(this.getClass().getName() + ".getContextMap built newContext:" + this.newContext + ".");

  System.out.println(this.getClass().getName() + ".getContextMap returning " + this.newContext.toString());
  return this.newContext;

 public void init(Map<String, String> arg0) throws PluginParseException {
  System.out.println(this.getClass().getName() + ".init invoked.");
  this.baseUrl = appPropsSvc.getPluginProperty(baseUrlKey, missingUrlVal);
  this.newContext = ImmutableMap.<String, Object>builder()
                   .put(baseUrlKey, baseUrl)
  System.out.println(this.getClass().getName() + ".init initialized newContext = " + this.newContext.toString());



1 answer




Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

710 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot