Skip to content
Permalink
Browse files

Merge pull request #30 from jenkinsci/bugfix/JENKINS-37370

Jenkins-37370
  • Loading branch information...
klimas7 committed Aug 22, 2016
2 parents 958e9a1 + 02ee09f commit cb8c8658db996035fd3d3f3441c55c751284ff76
@@ -367,12 +367,13 @@ private FilePathWrapper getTemporaryWorkspace() throws IOException {
}

private EnvVars getEnvironment(AbstractProject<?, ?> project) throws IOException, InterruptedException {
EnvVars environment = project.getEnvironment(Jenkins.getInstance().toComputer().getNode(), TaskListener.NULL);
if (project.getSomeBuildWithWorkspace() != null) {
return project.getSomeBuildWithWorkspace().getEnvironment(TaskListener.NULL);
} else {
return project.getEnvironment(null, TaskListener.NULL);
EnvVars buildEnvVars = project.getSomeBuildWithWorkspace().getEnvironment(TaskListener.NULL);
environment.putAll(buildEnvVars);
}

EnvVars.resolve(environment);
return environment;
}

private void initWorkspace(FilePathWrapper workspace, GitClient gitClient, URIish remoteURL) throws IOException, InterruptedException {
@@ -17,10 +17,13 @@
import java.util.Set;
import java.util.concurrent.ExecutionException;

import hudson.EnvVars;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.ParameterValue;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Result;
import hudson.model.TaskListener;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.UserRemoteConfig;
import hudson.tasks.Shell;
@@ -637,6 +640,36 @@ public void testGetDefaultValueAsTop() throws Exception {
assertEquals("0.1", def.getDefaultParameterValue().getValue());
}

@Test
public void testGlobalVariableRepositoryUrl() throws Exception {
EnvVars.masterEnvVars.put("GIT_REPO_URL",repositoryUrl);
project = jenkins.createFreeStyleProject("testGlobalValue");
project.getBuildersList().add(new Shell("echo test"));
setupGit("$GIT_REPO_URL");
GitParameterDefinition def = new GitParameterDefinition("testName",
GitParameterDefinition.PARAMETER_TYPE_BRANCH,
null,
"testDescription",
null,
".*master.*",
"*",
SortMode.ASCENDING, SelectedValue.NONE, false);

project.addProperty(new ParametersDefinitionProperty(def));
FreeStyleBuild build = project.scheduleBuild2(0).get();
assertEquals(build.getResult(), Result.SUCCESS);
ListBoxModel items = def.getDescriptor().doFillValueItems(project, def.getName());
assertTrue(isListBoxItem(items, "origin/master"));
}

private void setupGit(String url) throws IOException {
UserRemoteConfig config = new UserRemoteConfig(url, null, null, null);
List<UserRemoteConfig> configs = new ArrayList<UserRemoteConfig>();
configs.add(config);
GitSCM git = new GitSCM(configs, null, false, null, null, null, null);
project.setScm(git);
}

private boolean isListBoxItem(ListBoxModel items, String item) {
boolean itemExists = false;
for (int i = 0; i < items.size(); i++) {
@@ -648,10 +681,6 @@ private boolean isListBoxItem(ListBoxModel items, String item) {
}

private void setupGit() throws IOException {
UserRemoteConfig config = new UserRemoteConfig(repositoryUrl, null, null, null);
List<UserRemoteConfig> configs = new ArrayList<UserRemoteConfig>();
configs.add(config);
GitSCM git = new GitSCM(configs, null, false, null, null, null, null);
project.setScm(git);
setupGit(repositoryUrl);
}
}

0 comments on commit cb8c865

Please sign in to comment.
You can’t perform that action at this time.