Skip to content
Permalink
Browse files

Fixed JENKINS-33899 and JENKINS-32694

logging caused null exception. Improvements in exception logging.
  • Loading branch information
Sanketh P B
Sanketh P B committed Apr 8, 2016
1 parent f7cc436 commit 246f5a0ff1aedba561a32df77a913f28c712d9a6
@@ -86,18 +86,19 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
String tempFilePath = textFilePath;
if(this.useWorkspace && !(textFilePath.startsWith("${WORKSPACE}")||textFilePath.startsWith("$WORKSPACE")))
{
tempFilePath = "${WORKSPACE}" + System.getProperty("file.separator", "\\") + textFilePath;
tempFilePath = "${WORKSPACE}" + "/" + textFilePath;
}

String resolvedFilePath = build.getEnvironment(listener).expand(tempFilePath);
String resolvedContent = build.getEnvironment(listener).expand(textFileContent);

result = launcher.getChannel().call(new CreateFileTask(resolvedFilePath, resolvedContent, fileOption,listener));
result = launcher.getChannel().call(new CreateFileTask(resolvedFilePath, resolvedContent, fileOption, listener));


} catch (Exception e) {

listener.getLogger().println("Failed to create/update file.");
listener.getLogger().println(e.getMessage());
listener.getLogger().println("Failed to invoke 'CreateFileTask': " + e.getMessage());
e.printStackTrace(listener.getLogger());
return false;
}

@@ -42,14 +42,14 @@ of this software and associated documentation files (the "Software"), to deal
private final String fileContent;
private final String filePath;
private final String fileOption;
private static BuildListener listener;
private BuildListener listener;


public CreateFileTask(String filePath,String fileContent,String fileOption,BuildListener listener){
this.filePath = filePath;
this.fileContent = fileContent;
this.fileOption = fileOption;
CreateFileTask.listener = listener;
this.listener = listener;
}

@Override
@@ -106,8 +106,8 @@ public Boolean call() throws IOException {

} catch (Exception e) {

listener.getLogger().println("Failed to create/update file.");
listener.getLogger().println(e.getMessage());
listener.getLogger().println("Failed to create/update file. " + e.getMessage());
e.printStackTrace(listener.getLogger());
return false;
}
listener.getLogger().println("File successfully created/updated at "+ filePath);
@@ -60,7 +60,7 @@ public void testCreateNewFile() throws InterruptedException, IOException, Except
j.jenkins.getGlobalNodeProperties().add(prop);
FreeStyleProject project = j.createFreeStyleProject();

CreateFileBuilder builder = new CreateFileBuilder("${WORKSPACE}"+ System.getProperty("file.separator", "\\")+"${FILE_NAME}", "${LINE1}", "overWrite",false);
CreateFileBuilder builder = new CreateFileBuilder("${WORKSPACE}"+ "/" +"${FILE_NAME}", "${LINE1}", "overWrite",false);
project.getBuildersList().add(builder);
FreeStyleBuild build = project.scheduleBuild2(0).get();
String content = build.getWorkspace().child("NewFile.txt").readToString();
@@ -128,7 +128,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
});


CreateFileBuilder builder = new CreateFileBuilder("${WORKSPACE}"+ System.getProperty("file.separator", "\\")+"${FILE_NAME}", "${LINE2}", "appendToEnd",true);
CreateFileBuilder builder = new CreateFileBuilder("${WORKSPACE}"+ "/" +"${FILE_NAME}", "${LINE2}", "appendToEnd",true);
project.getBuildersList().add(builder);
FreeStyleBuild build = project.scheduleBuild2(0).get();
String filePath = build.getWorkspace().child("ExistingFile.txt").getRemote();

0 comments on commit 246f5a0

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