Skip to content

Commit

Permalink
Fixed JENKINS-33899 and JENKINS-32694
Browse files Browse the repository at this point in the history
logging caused null exception. Improvements in exception logging.
  • Loading branch information
Sanketh P B committed Apr 8, 2016
1 parent f7cc436 commit 246f5a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Expand Up @@ -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;
}

Expand Down
Expand Up @@ -42,14 +42,14 @@ public class CreateFileTask implements Serializable,Callable<Boolean,IOException
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
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 246f5a0

Please sign in to comment.