Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Assign webhook settings to a configuration in groovy #4278

beglowac ·

Is there any way to modify the webhook settings for a configuration using code? I'd like to write some groovy code in a build that walks a series of existing Quickbuild configurations and enables GitHub Webhooks - and also updates the Trigger User and Webhook Secret controls at the same time.

  • replies 1
  • views 977
  • stars 0
steveluo ADMIN ·

@beglowac please use below script to update/create the GitHub Webhooks:

groovy:

import java.util.List;
import java.util.ArrayList;

import com.pmease.quickbuild.Property;
import com.pmease.quickbuild.plugin.webhook.github.GitHubWebHookSetting;
import com.pmease.quickbuild.pluginsupport.PluginManager;
import com.pmease.quickbuild.Context;
import com.pmease.quickbuild.plugin.webhook.github.GitHubWebHookPlugin;

GitHubWebHookSetting setting = PluginManager.instance.getPlugin(GitHubWebHookPlugin.class)
    .findConfigurationSetting(Context.getConfiguration, false);
	
if (setting == null) {
    setting = new GitHubWebHookSetting();
}

setting.setSecret("1234567");
setting.setUsername("admin"); // the username of trigger user
setting.setCondition("return true"); // trigger condition
List<Property> variables = new ArrayList();
variables.add(new Property("name", "value"));
setting.setVariables(variables);

PluginManager.instance.getPlugin(GitHubWebHookPlugin.class).saveConfigurationSetting(Context.getConfiguration(), setting);

Please change Context.getConfiguration() to the configuration you want accordingly as Context.getConfiguration() returns the configuration you are running the step.