/** * Creates a {@link FreeStyleProject} with a gerrit-trigger dynamically configured. * * @param rule the instance of JenkinsRule. * @param name the name of the new job. * @param branchSetting the dynamic branch setting with operator e.g. "^**" or "=branch" * @return the project. * * @throws Exception if so. */ public static FreeStyleProject createGerritDynamicTriggeredJob(JenkinsRule rule, String name, String branchSetting) throws Exception { FreeStyleProject p = rule.createFreeStyleProject(name); List<GerritProject> projects = new LinkedList<GerritProject>(); File file = File.createTempFile("dynamic", "txt"); FileWriter fw = new FileWriter(file); fw.write("p=project\n"); fw.write("b" + branchSetting); fw.close(); List<PluginGerritEvent> list = new LinkedList<PluginGerritEvent>(); URI uri = file.toURI(); String filepath = uri.toURL().toString(); GerritTrigger trigger = new GerritTrigger(projects, null, null, null, null, null, null, null, null, null, null, null, false, false, false, false, false, null, null, null, null, null, null, null, null, PluginImpl.DEFAULT_SERVER_NAME, null, list, true, filepath, null); p.addTrigger(trigger); rule.submit(rule.createWebClient().getPage(p, "configure").getFormByName("config")); return p; }
/** * Creates a {@link FreeStyleProject} with a gerrit-trigger configured for a specific server name. * * @param rule the instance of JenkinsRule. * @param projectName the name of the new job. * @param serverName of your server * @return the project. * * @throws Exception if so. * @deprecated use {@link TestUtils.JobBuilder} instead. */ @Deprecated public static FreeStyleProject createGerritTriggeredJob(JenkinsRule rule, String projectName, String serverName) throws Exception { FreeStyleProject p = rule.createFreeStyleProject(projectName); List<GerritProject> projects = new LinkedList<GerritProject>(); projects.add(new GerritProject(CompareType.ANT, "**", Collections.singletonList(new Branch(CompareType.ANT, "**")), null, null, null, false)); p.addTrigger(new GerritTrigger(projects, null, null, null, null, null, null, null, null, null, null, null, false, false, true, false, false, null, null, null, null, null, null, null, null, serverName, null, null, false, null, null)); return rule.configRoundtrip(p); }
/** * Creates FreeStyleProject with specified Gerrit Trigger * and configure it to be triggered on provided list of events. * * @param name the project name * @param trigger the trigger to attach * @param triggerOnEvents the list of event to be triggered on * @return configured project * @throws IOException in case of failure during project creation */ private FreeStyleProject createJobWithGerritTrigger(String name, GerritTrigger trigger, List<PluginGerritEvent> triggerOnEvents) throws IOException { FreeStyleProject project = jenkinsRule.createFreeStyleProject(name); project.addTrigger(trigger); trigger.setTriggerOnEvents(triggerOnEvents); trigger.start(project, true); return project; }
/** * Creates a {@link FreeStyleProject} with a gerrit-trigger configured with a specific server and Code Review +1. * * @param rule the instance of JenkinsRule. * @param name the name of the new job. * @param serverName the name of the GerritServer * @return the project. * * @throws Exception if so. */ public static FreeStyleProject createGerritTriggeredJobForCommentAdded(JenkinsRule rule, String name, String serverName) throws Exception { FreeStyleProject p = rule.createFreeStyleProject(name); List<GerritProject> projects = new LinkedList<GerritProject>(); projects.add(new GerritProject(CompareType.ANT, "**", Collections.singletonList(new Branch(CompareType.ANT, "**")), null, null, null, false)); PluginCommentAddedEvent event = new PluginCommentAddedEvent("Code-Review", "1"); List<PluginGerritEvent> list = new LinkedList<PluginGerritEvent>(); list.add(event); p.addTrigger(new GerritTrigger(projects, null, null, null, null, null, null, null, null, null, null, null, false, false, true, false, false, null, null, null, null, null, null, null, null, serverName, null, list, false, null, null)); rule.submit(rule.createWebClient().getPage(p, "configure").getFormByName("config")); return p; } }
/** * Subscribes the job to the specified event. * @param job the job. * @param event the event. * @throws Exception if so. */ public void subscribeJobToEvent(FreeStyleProject job, PatchsetCreated event) throws Exception { GerritTrigger trigger = spy(new GerritTrigger(null)); doReturn(new GerritTrigger.DescriptorImpl()).when(trigger, "getDescriptor"); job.addTrigger(trigger); trigger.start(job, true); when(trigger.isInteresting(event)).thenReturn(true); }
private FreeStyleProject createPostCommitTriggerJob() throws Exception { // Disable crumbs because HTMLUnit refuses to mix request bodies with // request parameters r.jenkins.setCrumbIssuer(null); FreeStyleProject p = r.createFreeStyleProject(); String url = "https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-ant"; SCMTrigger trigger = new SCMTrigger("0 */6 * * *"); p.setScm(new SubversionSCM(url)); p.addTrigger(trigger); trigger.start(p, true); return p; }
private FreeStyleProject createPostCommitTriggerJobMultipleSvnLocations() throws Exception { // Disable crumbs because HTMLUnit refuses to mix request bodies with // request parameters r.jenkins.setCrumbIssuer(null); FreeStyleProject p = r.createFreeStyleProject(); String[] urls = new String[] {"https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-ant", "https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-maven/"}; p.setScm(new SubversionSCM(urls, new String[] {"", ""})); SCMTrigger trigger = new SCMTrigger("0 */6 * * *"); p.addTrigger(trigger); trigger.start(p, true); return p; }
trigger.setDynamicTriggerConfiguration(dynamicTriggerConfiguration); if (job instanceof FreeStyleProject) { ((FreeStyleProject)job).addTrigger(trigger); } else if (job instanceof MatrixProject) { ((MatrixProject)job).addTrigger(trigger);