Skip to content

Commit

Permalink
Merge pull request #44 from jenkinsci/feature/JENKINS-40523
Browse files Browse the repository at this point in the history
Include Jenkins Project Name in Log message
  • Loading branch information
klimas7 committed Feb 4, 2017
2 parents d4972a1 + 638dcf5 commit 7fb1ef4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
Expand Up @@ -6,7 +6,6 @@
import hudson.FilePath;

public class FilePathWrapper {
private static final Logger LOGGER = Logger.getLogger(FilePathWrapper.class.getName());
private final FilePath filePath;
private Boolean isTemporary = false;

Expand Down
Expand Up @@ -75,6 +75,8 @@ public class GitParameterDefinition extends ParameterDefinition implements Compa
private String useRepository;
private Boolean quickFilterEnabled;

private String customJobName;

@DataBoundConstructor
public GitParameterDefinition(String name, String type, String defaultValue, String description, String branch,
String branchFilter, String tagFilter, SortMode sortMode, SelectedValue selectedValue,
Expand Down Expand Up @@ -142,7 +144,7 @@ public ParameterValue getDefaultParameterValue() {
return new GitParameterValue(getName(), valueItems.get(0).value);
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, Messages.GitParameterDefinition_unexpectedError(), e);
LOGGER.log(Level.SEVERE, getCustomeJobName() + Messages.GitParameterDefinition_unexpectedError(), e);
}
break;
case DEFAULT:
Expand Down Expand Up @@ -257,6 +259,7 @@ public int compareTo(GitParameterDefinition pd) {
}

public Map<String, String> generateContents(JobWrapper jobWrapper, GitSCM git) {
customJobName = jobWrapper.getCustomJobName();

Map<String, String> paramList = new LinkedHashMap<String, String>();
try {
Expand Down Expand Up @@ -285,7 +288,7 @@ public Map<String, String> generateContents(JobWrapper jobWrapper, GitSCM git) {
}
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, Messages.GitParameterDefinition_unexpectedError(), e);
LOGGER.log(Level.SEVERE, getCustomeJobName() + Messages.GitParameterDefinition_unexpectedError(), e);
String message = e.getMessage() + Messages.GitParameterDefinition_lookAtLog();
paramList.clear();
paramList.put(message, message);
Expand Down Expand Up @@ -314,7 +317,7 @@ private Set<String> getTag(GitClient gitClient, String gitUrl) throws Interrupte
tagSet.add(tagName.replaceFirst(REFS_TAGS_PATTERN, ""));
}
} catch (GitException e) {
LOGGER.log(Level.WARNING,Messages.GitParameterDefinition_getTag(), e);
LOGGER.log(Level.WARNING, getCustomeJobName() + Messages.GitParameterDefinition_getTag(), e);
}
return tagSet;
}
Expand Down Expand Up @@ -344,7 +347,7 @@ private Pattern compileBranchFilterPattern() {
try {
branchFilterPattern = Pattern.compile(branchFilter);
} catch (Exception e) {
LOGGER.log(Level.INFO, Messages.GitParameterDefinition_branchFilterNotValid(), e.getMessage());
LOGGER.log(Level.INFO, getCustomeJobName() + Messages.GitParameterDefinition_branchFilterNotValid(), e.getMessage());
branchFilterPattern = Pattern.compile(".*");
}
return branchFilterPattern;
Expand Down Expand Up @@ -440,7 +443,7 @@ private void initWorkspace(FilePathWrapper workspace, GitClient gitClient, URIis
if (isEmptyWorkspace(workspace.getFilePath())) {
gitClient.init();
gitClient.clone(remoteURL.toASCIIString(), DEFAULT_REMOTE, false, null);
LOGGER.log(Level.INFO, Messages.GitParameterDefinition_genContentsCloneDone());
LOGGER.log(Level.INFO, getCustomeJobName() + Messages.GitParameterDefinition_genContentsCloneDone());
}
}

Expand Down Expand Up @@ -490,6 +493,10 @@ public void setUseRepository(String useRepository) {
this.useRepository = StringUtils.isEmpty(StringUtils.trim(useRepository)) ? null : useRepository;
}

public String getCustomeJobName() {
return customJobName;
}

@Extension
public static class DescriptorImpl extends ParameterDescriptor {
private List<GitSCM> scms;
Expand Down
Expand Up @@ -40,4 +40,14 @@ public int getNextBuildNumber() {
public void updateNextBuildNumber(int nextBuildNumber) throws IOException {
job.updateNextBuildNumber(nextBuildNumber);
}

@Override
public String getJobName() {
return job.getFullName();
}

@Override
public String getCustomJobName() {
return "[ " + getJobName() + " ] ";
}
}
Expand Up @@ -27,4 +27,8 @@ public interface JobWrapper {
int getNextBuildNumber();

void updateNextBuildNumber(int nextBuildNumber) throws IOException;

String getJobName();

String getCustomJobName();
}
Expand Up @@ -48,7 +48,7 @@ private SCM getSCMFromDefinition() {
return (SCM) scm;
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, Messages.WorkflowJobWrapper_GetWorkflowRepoScmFail(), e);
LOGGER.log(Level.SEVERE, getCustomJobName() + Messages.WorkflowJobWrapper_GetWorkflowRepoScmFail(), e);
}
return null;
}
Expand Down Expand Up @@ -76,7 +76,7 @@ public EnvVars getSomeBuildEnvironments() {
}
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, Messages.WorkflowJobWrapper_GetEnvironmentsFromWorkflowrun(), e);
LOGGER.log(Level.SEVERE, getCustomJobName() + Messages.WorkflowJobWrapper_GetEnvironmentsFromWorkflowrun(), e);
}
return null;
}
Expand Down

0 comments on commit 7fb1ef4

Please sign in to comment.