Skip to content

Commit

Permalink
Merge pull request #57 from blanked/support-views
Browse files Browse the repository at this point in the history
Added support for views
  • Loading branch information
cashlalala committed Sep 24, 2019
2 parents 0114296 + ca4956a commit b06f237
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.ParameterizedRemoteTrigger;

import static java.lang.Math.min;
import static org.apache.commons.lang.StringUtils.isEmpty;
import static org.apache.commons.lang.StringUtils.trimToEmpty;
import static org.apache.commons.lang.StringUtils.trimToNull;
Expand Down Expand Up @@ -288,7 +289,7 @@ public List<String> getParameterList(BuildContext context) {
* Reads a file from the jobs workspace, and loads the list of parameters from
* with in it. It will also call ```getCleanedParameters``` before returning.
*
* @param build
* @param BuildContext context
* @return List<String> of build parameters
*/
private List<String> loadExternalParameterFile(BuildContext context) {
Expand Down Expand Up @@ -336,7 +337,7 @@ private void removeEmptyElements(Collection<String> collection) {
* that no type of character encoding is happening at this step. All encoding
* happens in the "buildUrlQueryString" method.
*
* @param List <String> parameters
* @param List<String> parameters
* @return List<String> of build parameters
*/
private List<String> getCleanedParameters(List<String> parameters) {
Expand Down Expand Up @@ -510,7 +511,12 @@ private String getRootUrlFromJobUrl(String jobUrl) throws MalformedURLException
if (isEmpty(jobUrl))
return null;
if (FormValidationUtils.isURL(jobUrl)) {
int index = jobUrl.indexOf("/job/");
int index;
if (jobUrl.contains("/view/")) {
index = min(jobUrl.indexOf("/view/"), jobUrl.indexOf("/job/"));
} else {
index = jobUrl.indexOf("/job/");
}
if (index < 0)
throw new MalformedURLException("Expected '/job/' element in job URL but was: " + jobUrl);
return jobUrl.substring(0, index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import hudson.model.ParametersDefinitionProperty;
import hudson.model.StringParameterDefinition;
import hudson.model.User;
import hudson.model.ListView;
import hudson.security.HudsonPrivateSecurityRealm;
import hudson.security.SecurityRealm;
import hudson.security.AuthorizationStrategy.Unsecured;
Expand Down Expand Up @@ -520,4 +521,15 @@ public void testRemoteBuildWith5KByteString() throws Exception {
_testRemoteBuild(true, true, remoteProject, parms);
}

@Test
public void testRemoteViewBuild() throws Exception {
disableAuth();

FreeStyleProject remoteProject = jenkinsRule.createFreeStyleProject("test-job");
ListView view = new ListView("test-view", jenkinsRule.getInstance());
view.add(remoteProject);
jenkinsRule.getInstance().addView(view);
_testRemoteBuild(false, false, remoteProject);
}

}

0 comments on commit b06f237

Please sign in to comment.