/** * Get the relevant branch according to the user choice * * @param buildType - build instance * @param branchBean - bean that represents the branch that the user is on it * @return list with the relevant branch */ private BranchEx getCheckoutBranches(SBuildType buildType, BranchBean branchBean) { if(buildType instanceof BuildTypeEx) { ArrayList<BranchEx> branchExes = Lists.newArrayList(); BranchEx branch; //If the user is on the __all_branches__ view, take the default branch if (branchBean.isWildcardBranch()) { branch = ((BuildTypeEx) buildType).getBranch("<default>"); } else { String userBranch = branchBean.getUserBranch(); branch = ((BuildTypeEx) buildType).getBranch(userBranch); } branchExes.add(branch); return branch; } return null; }
private void addBuildTask(PolledTriggerContext context, List<TriggerTask> triggerTasks, PullRequest pullRequest) { PullRequestTarget source = pullRequest.getSource(); BuildTypeEx buildType = (BuildTypeEx) context.getBuildType(); BuildCustomizer buildCustomizer = buildCustomizerFactory.createBuildCustomizer(buildType, null); buildCustomizer.setCleanSources(true); Map<String, String> parameters = Maps.newHashMap(); parameters.put("trigger.pullRequestId", String.valueOf(pullRequest.getId())); buildCustomizer.setParameters(parameters); BranchEx branch = buildType.getBranchByDisplayName(source.getBranch().getName()); SVcsModification lastModification = checkChanges(source.getCommit().getHash(), branch.getDummyBuild().getChanges(SelectPrevBuildPolicy.SINCE_NULL_BUILD, true)); buildCustomizer.setDesiredBranchName(branch.getName()); if (lastModification != null) { buildCustomizer.setChangesUpTo(lastModification); } TriggerTask task = batchTrigger.newTriggerTask(buildCustomizer.createPromotion()); triggerTasks.add(task); }
BuildPromotionEx promotion = ((BuildTypeEx) buildType).createBuildPromotion(); promotion.setCustomParameters(customParameters); promotion.setDesiredBranchName(request.getParameter(ReleaseManagementParameterKeys.CHECKOUT_BRANCH));