@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); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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>" )) )); }
/** * 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)); }
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; }
@Override public ParameterValue createValue(StaplerRequest req) { String[] value = req.getParameterValues(getName()); if (value == null) { return getDefaultParameterValue(); } else if (value.length != 1) { throw new IllegalArgumentException(String.format( "Illegal number of parameter values for %s: %d", getName(), value.length)); } else { List<String> choices = getChoices(); if (choices.contains(value[0])) { return new StringParameterValue(getName(), value[0], getDescription()); } else { throw new IllegalArgumentException(String.format( "Value %s for parameter %s is not a valid choice.", value[0], getName())); } } }
@Override public Set<ParameterValue> getRunParameters() { Set<ParameterValue> parameters = new HashSet<ParameterValue>(); parameters.add(new StringParameterValue(KEY_REPO_NAME, getRepoName())); String host = getRegistryHost(); if (!StringUtils.isBlank(host)) { parameters.add(new StringParameterValue(KEY_DOCKER_HUB_HOST, host)); } String tag = getTag(); if (!StringUtils.isBlank(tag)) { parameters.add(new StringParameterValue(KEY_TAG, tag)); } String pusher = getPusher(); if (!StringUtils.isBlank(pusher)) { parameters.add(new StringParameterValue(KEY_PUSHER, pusher)); } return parameters; }
@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")); }
/** * 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; }
@Test public void testCreateValue() { GroovyScript script = new GroovyScript(new SecureGroovyScript(SCRIPT, Boolean.FALSE, null), new SecureGroovyScript(FALLBACK_SCRIPT, Boolean.FALSE, null)); ChoiceParameter param = new ChoiceParameter("name", "description", "some-random-name", script, "choiceType", true, 0); ParameterValue value = param.createValue("value"); assertEquals("value", value.getValue().toString()); JSONObject json = new JSONObject(); json.put("name", "name"); json.put("value", "value"); StaplerRequest request = PowerMockito.mock(StaplerRequest.class); PowerMockito.when(request.bindJSON(StringParameterValue.class, json)).thenReturn((StringParameterValue) value); value = param.createValue(request, json); assertEquals("value", value.getValue().toString()); }
private List<ParameterValue> getParametersValues(final Job job, final String branch) { final ParametersDefinitionProperty paramDefProp = (ParametersDefinitionProperty) job.getProperty(ParametersDefinitionProperty.class); final ArrayList<ParameterValue> defValues = new ArrayList<>(); for (final ParameterDefinition paramDefinition : paramDefProp.getParameterDefinitions()) { if ("BRANCH".equals(paramDefinition.getName())) { final StringParameterValue branchParam = new StringParameterValue("BRANCH", branch); defValues.add(branchParam); } else { final ParameterValue defaultValue = paramDefinition.getDefaultParameterValue(); if (defaultValue != null) defValues.add(defaultValue); } } return defValues; }
@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); }
@Override public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) { if (!(defaultValue instanceof StringParameterValue)) { //This should never happen return super.copyWithDefaultValue(defaultValue); } StringParameterValue spv = ((StringParameterValue) defaultValue); String value = spv.value; InheritableStringParameterReferenceDefinition isprd = new InheritableStringParameterReferenceDefinition( this.getName(), value ); isprd.setRootProperty(this.getRootProperty()); return isprd; }
/** * This function is invoked, when the user creates the value from an HTML * form request. This happens, for example, when a build is triggered * through the GUI instead of through the CLI. * <p> * This function is what makes an inheritable parameter inheritable at all. * Here, the value entered by the user is combined with the values of its * parents. This may mean: * <ul> * <li>overwriting the parent's value,</li> * <li>ensuring that a particular value is correctly set (if mandatory), * <li>that it does not overwrite a fixed value or</li> * <li>appending the parameter to its parent.</li> * </ul> * A complicating fact is that by default, a {@link ParameterDefinition} * is not informed for what kind of job is is being used, as that is not * a necessary piece of information in Vanilla-Jenkins. * * @see {@link #baseProject}. */ @Override public ParameterValue createValue(StaplerRequest req, JSONObject jo) { //First, we produce a temporary SPV from the JSON request StringParameterValue value = req.bindJSON( StringParameterValue.class, jo ); if (value == null) { //No such parameter name at all return null; } //Then, we check if we can get a properly derived value try { StringParameterValue dValue = this.produceDerivedValue(value.value); //Checking if that worked if (dValue == null) { return value; } else { return dValue; } } catch (IllegalArgumentException ex) { log.warning("Could not create inheritable string parameter: " + ex.toString()); return value; } }
public String getDerivedValue(String userEnteredValue, boolean noThrow) throws IllegalArgumentException { try { //Remove any prefix from parents, in case of a rebuild String val = this.stripInheritedPrefixFromValue(userEnteredValue); //Generate a full value based on that StringParameterValue spv = this.produceDerivedValue(val); if (spv == null) { return null; } return spv.value; } catch (IllegalArgumentException ex) { if (noThrow) { return null; } throw ex; } }
public static Map<String, String> getResolvedBuildParameters( InheritanceProject project ) { Map<String, String> result = new HashMap<String, String>(); List<ParameterDefinition> parameters = project.getParameters( IMode.INHERIT_FORCED ); for (ParameterDefinition pDef : parameters) { ParameterValue pVal = pDef.getDefaultParameterValue(); if (pVal instanceof StringParameterValue) { result.put( pDef.getName(), ((StringParameterValue) pVal).value ); } } //We do not resolve parameters; as they are most likely not complete anyway return result; }
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); } }
private void populatePromotionParameters(List<String> params, Object promotionObj) { final Promotion promotion = (Promotion) promotionObj; for (ParameterValue value : promotion.getParameterValues()) { if (value instanceof StringParameterValue) { if (StringUtils.isNotBlank(((StringParameterValue) value).value)) { params.add("<strong>" + value.getName() + "</strong>: " + ((StringParameterValue) value).value); } } else if (value instanceof FileParameterValue) { params.add("<strong>" + value.getName() + "</strong>: " + ((FileParameterValue) value).getLocation()); } else if (value instanceof BooleanParameterValue) { if (((BooleanParameterValue) value).value) { params.add("<strong>" + value.getName() + "</strong>: " + Boolean.toString(((BooleanParameterValue) value).value)); } } // TODO: there are more types } }
private List<StringParameterValue> getFilterParameters(@Nonnull RunSelectorContext context) { // Initialize.. parse out the given parameters/values. List<StringParameterValue> filters = new ArrayList<StringParameterValue>(5); Matcher m = PARAMVAL_PATTERN.matcher(context.getEnvVars().expand(getParamsToMatch())); while (m.find()) { filters.add(new StringParameterValue(m.group(1), m.group(2))); } return filters; }
/** * {@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; }
@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 />") ) )); }
@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() ); }
@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()); }
@Override public ParameterValue createValue(StaplerRequest req, JSONObject jo) { JSONArray jsonArray = (JSONArray)jo.get("value"); List<String> choices = getChoices(); List<String> selectionList = new ArrayList<>(); for(int i=0;i<choices.size();i++){ String choice = choices.get(i); if((Boolean)jsonArray.get(i)){ selectionList.add(choice); } } String selections = StringUtils.join(selectionList, ','); StringParameterValue value = new StringParameterValue(getName(), selections, getDescription()); return value; }
@Override // @Deprecated ??? public ParameterValue createValue(StaplerRequest req) { String[] value = req.getParameterValues(getName()); String selections = StringUtils.join(value, ','); return new StringParameterValue(getName(), selections, getDescription()); }
protected ParameterValue createValue() { // Runs the DSL and gets its result Object any = runDSL(); // Gets the value for this object String value = any != null ? getProperty(any, getValueProperty()) : ""; // Returns the string as a parameter return new StringParameterValue(getName(), value, getDescription()); }
@Override public Set<ParameterValue> getRunParameters() { Set<ParameterValue> parameters = new HashSet<ParameterValue>(); parameters.add(new StringParameterValue(KEY_REPO_NAME, getRepoName())); String host = getRegistryHost(); if (!StringUtils.isBlank(host)) { parameters.add(new StringParameterValue(KEY_DOCKER_REGISTRY_HOST, host)); } return parameters; }
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); }
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)); }
private void setCommitAuthor(GhprcCause cause, ArrayList<ParameterValue> values) { String authorName = ""; String authorEmail = ""; if (cause.getCommitAuthor() != null) { authorName = getString(cause.getCommitAuthor().getName(), ""); authorEmail = getString(cause.getCommitAuthor().getEmail(), ""); } values.add(new StringParameterValue("ghprcActualCommitAuthor", authorName)); values.add(new StringParameterValue("ghprcActualCommitAuthorEmail", authorEmail)); }
/** * 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; }
private static ParameterValue getStringParam(JSONObject formData, String paramName) { JSONObject paramObj = JSONObject.fromObject(formData.get(paramName)); String name = paramObj.getString("name"); FlakyTestResultAction.logger.log(Level.FINE, "Param: " + name + " with value: " + paramObj.getString("value")); return new StringParameterValue(name, paramObj.getString("value")); }
@Override public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) { if(defaultValue instanceof StringParameterValue) { StringParameterValue value = (StringParameterValue)defaultValue; return new PersistentChoiceParameterDefinition(getName(), getChoices(), value.value, successfulOnly, getDescription()); } else { return this; } }
@Override public ParameterValue createValue(StaplerRequest req, JSONObject jo) { StringParameterValue value = req.bindJSON(StringParameterValue.class, jo); value.setDescription(getDescription()); return checkValue(value); }
@Override public ParameterDefinition copyWithDefaultValue(ParameterValue defaultValue) { if(defaultValue instanceof StringParameterValue) { StringParameterValue value = (StringParameterValue)defaultValue; return new PersistentStringParameterDefinition(getName(), value.value, isSuccessfulOnly(), getDescription()); } else { return this; } }
@Override public ParameterValue createValue(StaplerRequest req, JSONObject jo) { StringParameterValue value = req.bindJSON(StringParameterValue.class, jo); value.setDescription(getDescription()); return value; }
@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)); }
@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)); }