Skip to content
Permalink
Browse files

JENKINS-34876 Git Parameters not working for Pipeline projects and Je…

…nkinsfile from SCM
  • Loading branch information
klimas7 committed Aug 31, 2016
1 parent 5fc8a95 commit b9c7ef390108df624f14c88a45b0be5156ebfe86
@@ -253,16 +253,16 @@ public int compareTo(GitParameterDefinition pd) {
return pd.uuid.equals(uuid) ? 0 : -1;
}

public Map<String, String> generateContents(JobWrapper IJobWrapper, GitSCM git) {
public Map<String, String> generateContents(JobWrapper jobWrapper, GitSCM git) {

Map<String, String> paramList = new LinkedHashMap<String, String>();
try {
EnvVars environment = getEnvironment(IJobWrapper);
EnvVars environment = getEnvironment(jobWrapper);
for (RemoteConfig repository : git.getRepositories()) {
boolean isRepoScm = REPO_SCM_NAME.equals(repository.getName());
synchronized (GitParameterDefinition.class) {
FilePathWrapper workspace = getWorkspace(IJobWrapper, isRepoScm);
GitClient gitClient = getGitClient(IJobWrapper, workspace, git, environment);
FilePathWrapper workspace = getWorkspace(jobWrapper, isRepoScm);
GitClient gitClient = getGitClient(jobWrapper, workspace, git, environment);
for (URIish remoteURL : repository.getURIs()) {
initWorkspace(workspace, gitClient, remoteURL);

@@ -348,8 +348,8 @@ private void sortAndPutToParam(Set<String> setElement, Map<String, String> param
return sorted;
}

private FilePathWrapper getWorkspace(JobWrapper jobImplementationWrapper, boolean isRepoScm) throws IOException, InterruptedException {
FilePathWrapper someWorkspace = new FilePathWrapper(jobImplementationWrapper.getSomeWorkspace());
private FilePathWrapper getWorkspace(JobWrapper jobWrapper, boolean isRepoScm) throws IOException, InterruptedException {
FilePathWrapper someWorkspace = new FilePathWrapper(jobWrapper.getSomeWorkspace());
if (isRepoScm) {
FilePath repoDir = new FilePath(someWorkspace.getFilePath(), REPO_MANIFESTS_DIR);
if (repoDir.exists()) {
@@ -373,9 +373,9 @@ private FilePathWrapper getTemporaryWorkspace() throws IOException {
return filePathWrapper;
}

private EnvVars getEnvironment(JobWrapper jobImplementationWrapper) throws IOException, InterruptedException {
EnvVars environment = jobImplementationWrapper.getEnvironment(Jenkins.getInstance().toComputer().getNode(), TaskListener.NULL);
EnvVars buildEnvironments = jobImplementationWrapper.getSomeBuildEnvironments();
private EnvVars getEnvironment(JobWrapper jobWrapper) throws IOException, InterruptedException {
EnvVars environment = jobWrapper.getEnvironment(Jenkins.getInstance().toComputer().getNode(), TaskListener.NULL);
EnvVars buildEnvironments = jobWrapper.getSomeBuildEnvironments();
if (buildEnvironments != null) {
environment.putAll(buildEnvironments);
}
@@ -395,13 +395,13 @@ private boolean isEmptyWorkspace(FilePath workspaceDir) throws IOException, Inte
return workspaceDir.list().size() == 0;
}

private GitClient getGitClient(final JobWrapper jobImplementationWrapper, FilePathWrapper workspace, GitSCM git, EnvVars environment) throws IOException, InterruptedException {
int nextBuildNumber = jobImplementationWrapper.getNextBuildNumber();
private GitClient getGitClient(final JobWrapper jobWrapper, FilePathWrapper workspace, GitSCM git, EnvVars environment) throws IOException, InterruptedException {
int nextBuildNumber = jobWrapper.getNextBuildNumber();

GitClient gitClient = git.createClient(TaskListener.NULL, environment, new Run(jobImplementationWrapper.getJob()) {
GitClient gitClient = git.createClient(TaskListener.NULL, environment, new Run(jobWrapper.getJob()) {
}, workspace.getFilePath());

jobImplementationWrapper.updateNextBuildNumber(nextBuildNumber);
jobWrapper.updateNextBuildNumber(nextBuildNumber);
return gitClient;
}

@@ -441,21 +441,21 @@ public String getDisplayName() {
public ListBoxModel doFillValueItems(@AncestorInPath Job job, @QueryParameter String param)
throws IOException, InterruptedException {
ListBoxModel items = new ListBoxModel();
JobWrapper IJobWrapper = JobWrapperFactory.createJobWrapper(job);
JobWrapper jobWrapper = JobWrapperFactory.createJobWrapper(job);

ParametersDefinitionProperty prop = IJobWrapper.getProperty(ParametersDefinitionProperty.class);
ParametersDefinitionProperty prop = jobWrapper.getProperty(ParametersDefinitionProperty.class);
if (prop != null) {
ParameterDefinition def = prop.getParameterDefinition(param);
if (def instanceof GitParameterDefinition) {
GitParameterDefinition paramDef = (GitParameterDefinition) def;

scm = getProjectSCM(IJobWrapper);
scm = getProjectSCM(jobWrapper);
if (scm == null) {
items.add(Messages.GitParameterDefinition_noRepositoryConfigured());
return items;
}

Map<String, String> paramList = paramDef.generateContents(IJobWrapper, scm);
Map<String, String> paramList = paramDef.generateContents(jobWrapper, scm);

for (Map.Entry<String, String> entry : paramList.entrySet()) {
items.add(entry.getValue(), entry.getKey());
@@ -465,10 +465,10 @@ public ListBoxModel doFillValueItems(@AncestorInPath Job job, @QueryParameter St
return items;
}

public GitSCM getProjectSCM(JobWrapper project) {
public GitSCM getProjectSCM(JobWrapper jobWrapper) {
SCM projectScm = null;
if (project != null) {
projectScm = project.getScm();
if (jobWrapper != null) {
projectScm = jobWrapper.getScm();
}

if (projectScm instanceof GitSCM) {

0 comments on commit b9c7ef3

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