Java 类hudson.model.ParametersAction 实例源码

项目:external-workspace-manager-plugin    文件:CustomWorkspaceTest.java   
@Test
public void customWorkspaceUsingPathParameter() throws Exception {
    WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, RandomStringUtils.randomAlphanumeric(7));
    job.setDefinition(new CpsFlowDefinition(format("" +
            "def customPath = \"${env.JOB_NAME}/${PR_BUILD_NUMBER}/${env.BUILD_NUMBER}\" \n" +
            "def extWorkspace = exwsAllocate diskPoolId: '%s', path: customPath \n" +
            "node { \n" +
            "   exws (extWorkspace) { \n" +
            "       writeFile file: 'foobar.txt', text: 'foobar' \n" +
            "   } \n" +
            "} \n", DISK_POOL_ID)));

    String prBuildNumberValue = "22";
    ParameterValue parameterValue = new StringParameterValue("PR_BUILD_NUMBER", prBuildNumberValue);
    ParametersAction parameterValues = new ParametersAction(parameterValue);

    WorkflowRun run = j.assertBuildStatusSuccess(job.scheduleBuild2(0, parameterValues));
    verifyWorkspacePath(format("%s/%s/%d", job.getFullName(), prBuildNumberValue, run.getNumber()), run);
}
项目:run-selector-plugin    文件:RunSelectorContext.java   
/**
 * Constructs the environment variables for the current build.
 *
 * @return the current build environment variables
 * @throws IOException
 * @throws InterruptedException
 */
private EnvVars constructEnvVars() throws IOException, InterruptedException {
    EnvVars envVars = build.getEnvironment(listener);
    if (build instanceof AbstractBuild) {
        envVars.putAll(((AbstractBuild<?, ?>) build).getBuildVariables()); // Add in matrix axes..
    } else {
        // Abstract#getEnvironment(TaskListener) put build parameters to
        // environments, but Run#getEnvironment(TaskListener) doesn't.
        // That means we can't retrieve build parameters from WorkflowRun
        // as it is a subclass of Run, not of AbstractBuild.
        // We need expand build parameters manually.
        // See JENKINS-26694, JENKINS-30357 for details.
        for (ParametersAction pa : build.getActions(ParametersAction.class)) {
            // We have to extract parameters manually as ParametersAction#buildEnvVars
            // (overrides EnvironmentContributingAction#buildEnvVars)
            // is applicable only for AbstractBuild.
            for (ParameterValue pv : pa.getParameters()) {
                pv.buildEnvironment(build, envVars);
            }
        }
    }

    return envVars;
}
项目:run-selector-plugin    文件:ParameterizedRunSelectorTest.java   
/**
 * Should not cause a fatal error even for a broken selectors.
 */
@Test
public void testBrokenParameter() throws Exception {
    FreeStyleProject jobToSelect = j.createFreeStyleProject();
    FreeStyleProject selecter = j.createFreeStyleProject();

    RunSelector selector = new ParameterizedRunSelector("${SELECTOR}");
    Run run = (Run) selecter.scheduleBuild2(
            0,
            new ParametersAction(
                    new StringParameterValue("SELECTOR", "<SomeBrokenSelector")
            )
    ).get();
    j.assertBuildStatusSuccess(run);

    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL));
    assertThat(selectedRun, nullValue());
}
项目:run-selector-plugin    文件:ParameterizedRunSelectorTest.java   
/**
 * Should not cause a fatal error even for an unavailable selectors.
 */
@Test
public void testUnavailableSelector() throws Exception {
    FreeStyleProject jobToSelect = j.createFreeStyleProject();
    FreeStyleProject selecter = j.createFreeStyleProject();

    RunSelector selector = new ParameterizedRunSelector("${SELECTOR}");
    Run run = (Run) selecter.scheduleBuild2(
            0,
            new ParametersAction(
                    new StringParameterValue("SELECTOR", "<NoSuchSelector />")
            )
    ).get();
    j.assertBuildStatusSuccess(run);

    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL));
    assertThat(selectedRun, nullValue());
}
项目:run-selector-plugin    文件:ParameterizedRunSelectorTest.java   
/**
 * Should not cause a fatal error even for an empty selectors.
 */
@Test
public void testEmptySelector() throws Exception {
    FreeStyleProject jobToSelect = j.createFreeStyleProject();
    FreeStyleProject selecter = j.createFreeStyleProject();

    RunSelector selector = new ParameterizedRunSelector("${SELECTOR}");
    Run run = (Run) selecter.scheduleBuild2(
            0,
            new ParametersAction(
                    new StringParameterValue("SELECTOR", "")
            )
    ).get();
    j.assertBuildStatusSuccess(run);

    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL));
    assertThat(selectedRun, nullValue());
}
项目:run-selector-plugin    文件:ParameterizedRunSelectorTest.java   
/**
 * Also accepts immediate value.
 */
@Test
public void testImmediateValue() throws Exception {
    // Prepare an artifact to be copied.
    FreeStyleProject jobToSelect = j.createFreeStyleProject();
    Run runToSelect = j.assertBuildStatusSuccess(jobToSelect.scheduleBuild2(0));

    WorkflowJob selecter = createWorkflowJob();
    selecter.setDefinition(new CpsFlowDefinition(String.format("" +
            "def runWrapper = selectRun job: '%s', " +
            " selector: [$class: 'ParameterizedRunSelector', parameterName: '${SELECTOR}'] \n" +
            "assert(runWrapper.id == '%s')", jobToSelect.getFullName(), runToSelect.getId())));

    j.assertBuildStatusSuccess(selecter.scheduleBuild2(
            0,
            null,
            new ParametersAction(new StringParameterValue(
                    "SELECTOR", "<StatusRunSelector><buildStatus>STABLE</buildStatus></StatusRunSelector>"
            ))
    ));
}
项目:run-selector-plugin    文件:ParameterizedRunSelectorTest.java   
/**
 * Also accepts variable expression.
 */
@Test
public void testVariableExpression() throws Exception {
    FreeStyleProject jobToSelect = j.createFreeStyleProject();
    Run runToSelect = j.assertBuildStatusSuccess(jobToSelect.scheduleBuild2(0));

    FreeStyleProject selecter = j.createFreeStyleProject();
    RunSelector selector = new ParameterizedRunSelector("${SELECTOR}");

    Run run = j.assertBuildStatusSuccess(selecter.scheduleBuild2(
            0,
            (Cause) null,
            new ParametersAction(new StringParameterValue(
                    "SELECTOR",
                    "<StatusRunSelector><buildStatus>STABLE</buildStatus></StatusRunSelector>"
            ))
    ));
    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL));
    assertThat(selectedRun, is(runToSelect));
}
项目:openshift-sync-plugin    文件:JenkinsUtils.java   
public static List<Action> setJobRunParamsFromEnvAndUIParams(WorkflowJob job, JenkinsPipelineBuildStrategy strat,
        List<Action> buildActions, ParametersAction params) {
    List<EnvVar> envs = strat.getEnv();
    List<ParameterValue> envVarList = new ArrayList<ParameterValue>();
    if (envs.size() > 0) {
        // build list of env var keys for compare with existing job params
        for (EnvVar env : envs) {
            envVarList.add(new StringParameterValue(env.getName(), env.getValue()));
        }
    }

    if (params != null)
        envVarList.addAll(params.getParameters());

    if (envVarList.size() > 0)
        buildActions.add(new ParametersAction(envVarList));

    return buildActions;
}
项目:fabric8-jenkins-workflow-steps    文件:Runs.java   
public static Map<String, Object> getBuildParameters(Run build) {
    List<ParametersAction> actions = build.getActions(ParametersAction.class);
    if (actions != null) {
        Map<String, Object> answer = new HashMap<String, Object>();
        for (ParametersAction action : actions) {
            List<ParameterValue> parameters = action.getParameters();
            if (parameters != null) {
                for (ParameterValue parameter : parameters) {
                    String name = parameter.getName();
                    Object value = parameter.getValue();
                    answer.put(name, value);
                }
            }
        }
        return answer;
    }
    return null;
}
项目:fabric8-jenkins-workflow-steps    文件:Steps.java   
public static Object buildParameterOrNull(TaskListener listener, FlowExecution flowExecution, String parameter, String defaultValue) throws IOException {
    if (Strings.isNullOrBlank(parameter)) {
        log(listener, "No parameter name!");
    } else {
        Run<?, ?> run = $build(flowExecution);
        ParametersAction action = null;
        if (run != null) {
            action = run.getAction(ParametersAction.class);
        } else {
            log(listener, "No $build could be found from flowExecution " + flowExecution);
        }
        if (action == null) {
            log(listener, "No ParametersAction could be found!");
        } else {
            ParameterValue parameterValue = action.getParameter(parameter);
            if (parameterValue == null) {
                log(listener, "No ParameterValue could be found for '" + parameter + "'");
            } else {
                return parameterValue.getValue();
            }
        }
    }
    return defaultValue;
}
项目:jenkins-deployment-dashboard-plugin    文件:EnvironmentTagBuilder.java   
private DeployJobVariables extractDeployJobVariables(AbstractBuild build) {
    String environment = DeployJobVariablesBuilder.UNDEFINED;
    String version = DeployJobVariablesBuilder.UNDEFINED;
    List<ParametersAction> actionList = Util.filter(build.getAllActions(), ParametersAction.class);
    for (ParametersAction parametersAction : actionList) {
        List<ParameterValue> params = parametersAction.getParameters();
        for (ParameterValue parameterValue : params) {
            if (DashboardView.PARAM_ENVIRONMENT.equalsIgnoreCase((String) parameterValue.getName())) {
                environment = (String) parameterValue.getValue();
            }
            if (DashboardView.PARAM_VERSION.equalsIgnoreCase((String) parameterValue.getName())) {
                version = (String) parameterValue.getValue();
            }
        }
    }
    return DeployJobVariablesBuilder.createBuilder().version(version).environment(environment).build();
}
项目:yaml-project-plugin    文件:YamlBuild.java   
/** Get the default parameter values for the given delegate */
private ParametersAction getDefaultParametersValues(
    AbstractProject delegate) {
  final ParametersDefinitionProperty property =
      (ParametersDefinitionProperty) delegate.getProperty(
          ParametersDefinitionProperty.class);
  if (property == null) {
    return null;
  }

  final List<ParameterValue> result = Lists.newArrayList();
  for (ParameterDefinition def : property.getParameterDefinitions()) {
    ParameterValue value = def.getDefaultParameterValue();
    if (value != null) {
      result.add(value);
    }
  }

  return new ParametersAction(result);
}
项目:yaml-project-plugin    文件:YamlProjectTest.java   
@Test
public void testSimpleWithParameter() throws Exception {
  writeResourceToFile("param.yaml");

  assertEquals(0, underTest.getItems().size());

  ParametersAction parameters = new ParametersAction(
      new StringParameterValue("foo", "baz"));
  YamlBuild build = underTest.scheduleBuild2(0,
      new Cause.LegacyCodeCause(), parameters).get();

  dumpLog(build);
  assertEquals(Result.SUCCESS, build.getResult());
  assertThat(CharStreams.toString(new InputStreamReader(
      build.getLogInputStream())),
      // Check that we wrote the passed in parameter instead
      // of the default value.
      containsString("baz"));
}
项目:ghprb-copy    文件:GhprbTrigger.java   
/**
 * Find the previous BuildData for the given pull request number; this may return null
 */
private BuildData findPreviousBuildForPullId(StringParameterValue pullIdPv) {
    // find the previous build for this particular pull requet, it may not be the last build
    for (Run<?,?> r : job.getBuilds()) {
        ParametersAction pa = r.getAction(ParametersAction.class);
        if (pa != null) {
            for (ParameterValue pv : pa.getParameters()) {
                if (pv.equals(pullIdPv)) {
                    for (BuildData bd : r.getActions(BuildData.class)) {
                        return bd;
                    }
                }
            }
        }
    }
    return null;
}
项目:DotCi    文件:GithubWebhookTest.java   
@Test
public void should_trigger_build_with_default_parameter_values() throws IOException, InterruptedException {
    final StaplerRequest request = mock(StaplerRequest.class);
    when(request.getParameter("payload")).thenReturn("payload");
    final DynamicProject project = mock(DynamicProject.class);

    final ParameterDefinition branchParameter = mock(ParameterDefinition.class);
    when(branchParameter.getName()).thenReturn("BRANCH");

    final ParameterDefinition secondParameter = mock(ParameterDefinition.class);
    when(branchParameter.getName()).thenReturn("PARAM");
    when(secondParameter.getDefaultParameterValue()).thenReturn(new StringParameterValue("PARAM", "meow"));
    final ParametersDefinitionProperty paramDefinition = mock(ParametersDefinitionProperty.class);
    when(paramDefinition.getParameterDefinitions()).thenReturn(Arrays.asList(branchParameter, secondParameter));
    when(project.getProperty(ParametersDefinitionProperty.class)).thenReturn(paramDefinition);

    kickOffBuildTrigger(request, project);

    final ArgumentCaptor<ParametersAction> parametersCaptor = ArgumentCaptor.forClass(ParametersAction.class);
    verify(project).scheduleBuild(eq(0), any(GithubPushPullWebhookCause.class), parametersCaptor.capture());

    final ParametersAction parametersAction = parametersCaptor.getValue();
    Assert.assertTrue(parametersAction.getParameter("PARAM") instanceof StringParameterValue);
    Assert.assertEquals("meow", ((StringParameterValue) parametersAction.getParameter("PARAM")).value);

}
项目:jenkins-inheritance-plugin    文件:BuildViewExtension.java   
public static final void mergeParameters(List<Action> actions) {
    List<ParameterValue> pv = new LinkedList<ParameterValue>();
    Iterator<Action> iter = actions.iterator();
    while (iter.hasNext()) {
        Action a = iter.next();
        if (!(a instanceof ParametersAction)) {
            continue;
        }
        ParametersAction pa = (ParametersAction) a;
        pv.addAll(pa.getParameters());
        iter.remove();
    }
    if (!pv.isEmpty()) {
        actions.add(new ParametersAction(pv));
    }
}
项目:jenkins-inheritance-plugin    文件:TestInheritanceMain.java   
public InheritanceBuild buildAndAssertValue(XmlProject p, String param, String value, boolean assertSuccess) throws IOException {
    try {
        InheritanceBuild build = (assertSuccess)
                ? jRule.buildAndAssertSuccess(p.project)
                : p.project.scheduleBuild2(0).get();
        Assert.assertNotNull(build);
        ParametersAction pa = build.getAction(ParametersAction.class);
        Assert.assertNotNull("Build has no parameters", pa);

        ParameterValue pv = pa.getParameter(param);
        Assert.assertNotNull("Build has no parameter P", pv);
        Assert.assertTrue("Parameter is not a StringParameterValue", pv instanceof StringParameterValue);
        Assert.assertEquals("Parameter does not have correct value", value, ((StringParameterValue)pv).value);
        return build;
    } catch (Exception e) {
        throw new IOException(e);
    }
}
项目:delivery-pipeline-plugin    文件:DeliveryPipelineView.java   
@Override
public void triggerRebuild(String projectName, String buildId) {
    AbstractProject project = ProjectUtil.getProject(projectName, Jenkins.getInstance());
    if (!project.hasPermission(Item.BUILD)) {
        throw new BadCredentialsException("Not authorized to trigger build");
    }
    AbstractBuild build = project.getBuildByNumber(Integer.parseInt(buildId));

    @SuppressWarnings("unchecked")
    List<Cause> prevCauses = build.getCauses();
    List<Cause> newCauses = new ArrayList<>();
    for (Cause cause : prevCauses) {
        if (!(cause instanceof Cause.UserIdCause)) {
            newCauses.add(cause);
        }
    }
    newCauses.add(new Cause.UserIdCause());
    CauseAction causeAction = new CauseAction(newCauses);
    project.scheduleBuild2(project.getQuietPeriod(),null, causeAction, build.getAction(ParametersAction.class));
}
项目:run-selector-plugin    文件:ParametersRunFilter.java   
/**
 * {@inheritDoc}
 */
@Override
public boolean isSelectable(@Nonnull Run<?,?> run, @Nonnull RunSelectorContext context) {
    EnvVars otherEnv;
    try {
        otherEnv = run.getEnvironment(TaskListener.NULL);
    } catch (Exception ex) {
        return false;
    }
    if(!(run instanceof AbstractBuild)) {
        // Abstract#getEnvironment(TaskListener) put build parameters to
        // environments, but Run#getEnvironment(TaskListener) doesn't.
        // That means we can't retrieve build parameters from WorkflowRun
        // as it is a subclass of Run, not of AbstractBuild.
        // We need expand build parameters manually.
        // See JENKINS-26694 for details.
        for(ParametersAction pa: run.getActions(ParametersAction.class)) {
            // We have to extract parameters manally as ParametersAction#buildEnvVars
            // (overrides EnvironmentContributingAction#buildEnvVars)
            // is applicable only for AbstractBuild.
            for(ParameterValue pv: pa.getParameters()) {
                pv.buildEnvironment(run, otherEnv);
            }
        }
    }
    List<StringParameterValue> filters = getFilterParameters(context);
    for (StringParameterValue spv : filters) {
        if (!spv.value.equals(otherEnv.get(spv.getName()))) {
            context.logDebug(
                    "{0}: {1} is declined",
                    getDisplayName(),
                    run.getDisplayName()
            );
            return false;
        }
    }
    return true;
}
项目:run-selector-plugin    文件:ParameterizedRunFilterTest.java   
@Test
public void testIsSelectableWithParameter() throws Exception {
    WorkflowJob selecter = j.jenkins.createProject(
        WorkflowJob.class,
        RandomStringUtils.randomAlphanumeric(7)
    );
    selecter.addProperty(new ParametersDefinitionProperty(
        new RunFilterParameter(
            "FILTER",
            "description",
            new NoRunFilter()
        )
    ));
    selecter.setDefinition(new CpsFlowDefinition(String.format(
        "def runWrapper = selectRun"
        + " job: '%s',"
        + " filter: [$class: 'ParameterizedRunFilter', parameter: '${FILTER}'],"
        + " verbose: true;"
        + "assert(runWrapper.id == '%s')",
        jobToSelect.getFullName(),
        runToSelect1.getId()
    )));

    j.assertBuildStatusSuccess(selecter.scheduleBuild2(
        0,
        new ParametersAction(
            new StringParameterValue("FILTER", "<SavedRunFilter />")
        )
    ));
}
项目:run-selector-plugin    文件:ParameterizedRunFilterTest.java   
@Test
public void testIsSelectableBadParameter() throws Exception {
    WorkflowJob selecter = j.jenkins.createProject(
        WorkflowJob.class,
        RandomStringUtils.randomAlphanumeric(7)
    );
    selecter.addProperty(new ParametersDefinitionProperty(
        new RunFilterParameter(
            "FILTER",
            "description",
            new NoRunFilter()
        )
    ));
    selecter.setDefinition(new CpsFlowDefinition(String.format(
        "def runWrapper = selectRun"
        + " job: '%s',"
        + " filter: [$class: 'ParameterizedRunFilter', parameter: '${FILTER}'],"
        + " verbose: true;",
        jobToSelect.getFullName()
    )));

    j.assertBuildStatus(
        Result.FAILURE,
        selecter.scheduleBuild2(
            0,
            new ParametersAction(
                new StringParameterValue("FILTER", "Bad Parameter")
            )
        ).get()
    );
}
项目:run-selector-plugin    文件:DisplayNameRunFilterTest.java   
@Test
public void testDisplayName() throws Exception {
    jobToSelect.getBuildByNumber(2).setDisplayName("RC1");

    FreeStyleProject selecter = j.createFreeStyleProject();
    RunSelector selector = new StatusRunSelector();
    RunFilter filter = new DisplayNameRunFilter("$NUM");

    Run run = j.assertBuildStatusSuccess(selecter.scheduleBuild2(
            0,
            new Cause.UserIdCause(),
            new ParametersAction(
                    new StringParameterValue("NUM", "RC1")
            )
    ));
    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL, filter));
    assertThat(selectedRun.getNumber(), is(2));

    run = j.assertBuildStatusSuccess(selecter.scheduleBuild2(
            0,
            new Cause.UserIdCause(),
            new ParametersAction(
                    new StringParameterValue("NUM", "RC2")
            )
    ));
    selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL, filter));
    assertThat(selectedRun, nullValue());
}
项目:openshift-sync-plugin    文件:BuildToActionMapper.java   
static synchronized void initialize() {
    if (buildToParametersMap == null) {
        buildToParametersMap = new ConcurrentHashMap<String, ParametersAction>();
    }
    if (buildToCauseMap == null) {
        buildToCauseMap = new ConcurrentHashMap<String, CauseAction>();
    }
}
项目:openshift-sync-plugin    文件:BuildDecisionHandler.java   
private static ParametersAction dumpParams(List<Action> actions) {
    for (Action action : actions) {
        if (action instanceof ParametersAction) {
            ParametersAction paramAction = (ParametersAction) action;
            if (LOGGER.isLoggable(Level.FINE))
                for (ParameterValue param : paramAction.getAllParameters()) {
                    LOGGER.fine("param name " + param.getName()
                            + " param value " + param.getValue());
                }
            return paramAction;
        }
    }
    return null;
}
项目:phabricator-jenkins-plugin    文件:PhabricatorBuildWrapper.java   
@VisibleForTesting
static String getAbortOnRevisionId(AbstractBuild build) {
    ParametersAction parameters = build.getAction(ParametersAction.class);
    if (parameters != null) {
        ParameterValue parameterValue = parameters.getParameter(
                PhabricatorPlugin.ABORT_ON_REVISION_ID_FIELD);
        if (parameterValue != null) {
            return (String) parameterValue.getValue();
        }
    }
    return null;
}
项目:github-integration-plugin    文件:JobHelper.java   
public static boolean rebuild(Run<?, ?> run) {
    final QueueTaskFuture queueTaskFuture = asParameterizedJobMixIn(run.getParent())
            .scheduleBuild2(
                    0,
                    run.getAction(ParametersAction.class),
                    run.getAction(CauseAction.class),
                    run.getAction(BuildBadgeAction.class)
            );
    return queueTaskFuture != null;
}
项目:github-integration-plugin    文件:JobRunnerForCauseTest.java   
public static QueueTaskFuture schedule(Job<?, ?> job, int number, String param, int queuetPeriod) {
    ParameterizedJobMixIn jobMixIn = JobInfoHelpers.asParameterizedJobMixIn(job);
    GitHubPRCause cause = newGitHubPRCause().withNumber(number);
    ParametersAction parametersAction = new ParametersAction(
            Collections.<ParameterValue>singletonList(new StringParameterValue("value", param))
    );
    return jobMixIn.scheduleBuild2(queuetPeriod, new CauseAction(cause), parametersAction);
}
项目:jenkins-github-pull-request-comments    文件:GhprcTrigger.java   
public QueueTaskFuture<?> startJob(GhprcCause cause, GhprcRepository repo) {
    ArrayList<ParameterValue> values = getDefaultParameters();
    final String commitSha = cause.isMerged() ? "origin/pr/" + cause.getPullID() + "/merge" : cause.getCommit();
    values.add(new StringParameterValue("sha1", commitSha));
    values.add(new StringParameterValue("ghprcActualCommit", cause.getCommit()));

    setCommitAuthor(cause, values);

    final StringParameterValue pullIdPv = new StringParameterValue("ghprcPullId", String.valueOf(cause.getPullID()));
    values.add(pullIdPv);
    values.add(new StringParameterValue("ghprcTargetBranch", String.valueOf(cause.getTargetBranch())));
    values.add(new StringParameterValue("ghprcSourceBranch", String.valueOf(cause.getSourceBranch())));
    values.add(new StringParameterValue("GIT_BRANCH", String.valueOf(cause.getSourceBranch())));
    // it's possible the GHUser doesn't have an associated email address
    values.add(new StringParameterValue("ghprcPullAuthorEmail", getString(cause.getAuthorEmail(), "")));
    values.add(new StringParameterValue("ghprcPullDescription", String.valueOf(cause.getShortDescription())));
    values.add(new StringParameterValue("ghprcPullTitle", String.valueOf(cause.getTitle())));
    values.add(new StringParameterValue("ghprcPullLink", String.valueOf(cause.getUrl())));
    values.add(new StringParameterValue("ghprcOutputFile", getDescriptor().getOutputFile()));

    try {
        values.add(new StringParameterValue("ghprcTargetCommit",
                repo.getGitHubRepo().getBranches().get(cause.getTargetBranch()).getSHA1()));
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Unable to get branches from github repo", e);
    }

    // add the previous pr BuildData as an action so that the correct change log is generated by the GitSCM plugin
    // note that this will be removed from the Actions list after the job is completed so that the old (and incorrect)
    // one isn't there
    return this.job.scheduleBuild2(job.getQuietPeriod(), cause, new ParametersAction(values), findPreviousBuildForPullId(pullIdPv));
}
项目:jenkins-github-pull-request-comments    文件:GhprcTrigger.java   
/**
 * Find the previous BuildData for the given pull request number; this may return null
 */
private BuildData findPreviousBuildForPullId(StringParameterValue pullIdPv) {
    // find the previous build for this particular pull request, it may not be the last build
    for (Run<?, ?> r : job.getBuilds()) {
        ParametersAction pa = r.getAction(ParametersAction.class);
        if (pa != null) {
            for (ParameterValue pv : pa.getParameters()) {
                if (pv.equals(pullIdPv)) {
                    Iterables.getFirst(r.getActions(BuildData.class), null);
                }
            }
        }
    }
    return null;
}
项目:gitlab-plugin    文件:NoteBuildActionTest.java   
@Test
public void build_alreadyBuiltMR_alreadyBuiltMR() throws IOException, ExecutionException, InterruptedException {
    FreeStyleProject testProject = jenkins.createFreeStyleProject();
    testProject.addTrigger(trigger);
    testProject.setScm(new GitSCM(gitRepoUrl));
    QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new ParametersAction(new StringParameterValue("gitlabTargetBranch", "master")));
    future.get();

    exception.expect(HttpResponses.HttpResponseException.class);
    new NoteBuildAction(testProject, getJson("NoteEvent_alreadyBuiltMR.json"), null).execute(response);

    verify(trigger).onPost(any(NoteHook.class));
}
项目:gitlab-plugin    文件:MergeRequestBuildActionTest.java   
@Test
public void skip_alreadyBuiltMR() throws IOException, ExecutionException, InterruptedException {
    FreeStyleProject testProject = jenkins.createFreeStyleProject();
    testProject.addTrigger(trigger);
    testProject.setScm(new GitSCM(gitRepoUrl));
    QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new ParametersAction(new StringParameterValue("gitlabTargetBranch", "master")));
    future.get();

    exception.expect(HttpResponses.HttpResponseException.class);
    new MergeRequestBuildAction(testProject, getJson("MergeRequestEvent_alreadyBuiltMR.json"), null).execute(response);

    verify(trigger, never()).onPost(any(MergeRequestHook.class));
}
项目:ghprb-copy    文件:GhprbTrigger.java   
public QueueTaskFuture<?> startJob(GhprbCause cause){
    ArrayList<ParameterValue> values = getDefaultParameters();
    values.add(new StringParameterValue("sha1", cause.isMerged() ? "origin/pr/" + cause.getPullID() + "/merge" : cause.getCommit()));
    values.add(new StringParameterValue("ghprbActualCommit",cause.getCommit()));
    final StringParameterValue pullIdPv = new StringParameterValue("ghprbPullId",String.valueOf(cause.getPullID()));
    values.add(pullIdPv);
    values.add(new StringParameterValue("ghprbTargetBranch",String.valueOf(cause.getTargetBranch())));
    // it's possible the GHUser doesn't have an associated email address
    values.add(new StringParameterValue("ghprbPullAuthorEmail",cause.getAuthorEmail() != null ? cause.getAuthorEmail() : ""));

    // add the previous pr BuildData as an action so that the correct change log is generated by the GitSCM plugin
    // note that this will be removed from the Actions list after the job is completed so that the old (and incorrect)
    // one isn't there
    return this.job.scheduleBuild2(0,cause,new ParametersAction(values),findPreviousBuildForPullId(pullIdPv));
}
项目:p4-jenkins    文件:ReviewAction.java   
public void doBuild(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {

        project.checkPermission(AbstractProject.BUILD);

        List<ParameterValue> values = new ArrayList<ParameterValue>();
        List<ParameterDefinition> defs = new ArrayList<ParameterDefinition>();

        Enumeration<?> names = req.getParameterNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            defs.add(new StringParameterDefinition(name, null));
        }

        for (ParameterDefinition d : defs) {
            StringParameterValue value = (StringParameterValue) d.createValue(req);
            if (value != null && value.value != null && !value.value.isEmpty()) {
                values.add(value);
            }
        }

        // Schedule build
        TimeDuration delay = new TimeDuration(project.getQuietPeriod());
        CauseAction cause = new CauseAction(new Cause.UserIdCause());

        List<ParameterValue> internalParams = extractAndRemoveInternalParameters(values);
        ParametersAction params = new SafeParametersAction(values, internalParams);

        Jenkins j = Jenkins.getInstance();
        if (j != null) {
            Queue queue = j.getQueue();
            queue.schedule(project, delay.getTime(), params, cause);

            // send the user back to the job top page.
            rsp.sendRedirect("../");
        }
    }
项目:DotCi    文件:ProcessedBuild.java   
@Override
public List<ParameterValue> getParameters() {
    if (this.build.getAction(ParametersAction.class) != null) {
        return this.build.getAction(ParametersAction.class).getParameters();
    }
    return Lists.newArrayList();
}
项目:DotCi    文件:BuildEnvironment.java   
public boolean initialize() throws IOException, InterruptedException {
    final List<BuildWrapper> wrappers = new ArrayList<>(getProject().getBuildWrappers().values());
    final ParametersAction parameters = getAction(ParametersAction.class);
    if (parameters != null) {
        parameters.createBuildWrappers(this.build, wrappers);
    }
    return setupWrappers(wrappers);

}
项目:DotCi    文件:SubBuildScheduler.java   
protected void scheduleSubBuilds(final Iterable<Combination> subBuildCombinations, final SubBuildFinishListener subBuildFinishListener, final TaskListener listener) {
    for (final Combination subBuildCombination : subBuildCombinations) {
        final DynamicSubProject c = this.dynamicBuild.getSubProject(subBuildCombination);
        listener.getLogger().println(Messages.MatrixBuild_Triggering(ModelHyperlinkNote.encodeTo(c)));
        final List<Action> childActions = new ArrayList<>();
        childActions.addAll(Util.filter(this.dynamicBuild.getActions(), ParametersAction.class));
        childActions.add(new SubBuildExecutionAction(this.subBuildRunner, subBuildFinishListener));
        childActions.add(new ParentBuildAction(this.dynamicBuild));
        c.scheduleBuild(childActions, this.dynamicBuild.getCause());
    }
}
项目:DotCi    文件:DownstreamJobPlugin.java   
private String getSourceBuildNumber(DynamicBuild dynamicBuild) {
    if (dynamicBuild.getCause() instanceof DotCiUpstreamTriggerCause) {
        List<ParameterValue> params = dynamicBuild.getAction(ParametersAction.class).getParameters();
        for (ParameterValue param : params) {
            if (param.getName().equals("SOURCE_BUILD")) {
                return (String) param.getValue();
            }
        }
    }
    return "" + dynamicBuild.getNumber();
}
项目:DotCi    文件:GithubWebhookTest.java   
@Test
public void should_trigger_builds_for_payload() throws IOException, InterruptedException {
    final StaplerRequest request = mock(StaplerRequest.class);
    when(request.getParameter("payload")).thenReturn("payload");
    final DynamicProject project = mock(DynamicProject.class);
    final ParametersDefinitionProperty paramDefinition = mock(ParametersDefinitionProperty.class);
    when(project.getProperty(ParametersDefinitionProperty.class)).thenReturn(paramDefinition);

    kickOffBuildTrigger(request, project);

    verify(project).scheduleBuild(eq(0), any(GithubPushPullWebhookCause.class), any(ParametersAction.class));
}
项目:jenkins-inheritance-plugin    文件:InheritanceBuild.java   
protected Collection<ParameterValue> getParameterValues() {
    Map<String, ParameterValue> map = new HashMap<String, ParameterValue>();
    Run<?,?> run = this.getBuild();
    List<ParametersAction> actions =
            run.getActions(ParametersAction.class);

    for (ParametersAction pa : actions) {
        for (ParameterValue pv : pa.getParameters()) {
            if (pv == null || pv.getName() == null) { continue; }
            map.put(pv.getName(), pv);
        }
    }

    return map.values();
}