This is my first question on here so apologies if its not detailed enough. I am trying to set up a post-commit batch job for work that I am doing. I am using VisualSVN to manage my repository. I have the following post-commit.bat file:
REM Get the commit variables
SET REPOSITORY_PATH=%1
SET REVISION=%2
CD "C:\ProgramData\Oracle\Java\javapath"
java -jar "C:\Users\Nick\Developer\Repository\Restaurant_System\hooks\post_commit_hook.jar"
I then have the following jar file:
/**
*
*/
package svn.hooks;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
/**
* Name: post_commit_hook Purpose/Description: TODO
*/
public abstract class post_commit_hook {
/**
* Name: main Description: The main entry point of the program Returns: void
*/
public static void main(String[] args) {
try {
System.err.println("We're In!"); //This should send a message to the client committer (but it doesn't)
String[] command = { "CMD", "/C", "call", "C:/Scripts/svn-backup.bat"};
ProcessBuilder probuilder = new ProcessBuilder(command);
Map<String, String> env = probuilder.environment();
PrintWriter writer = new PrintWriter("C:/Users/Nick/Desktop/test.txt", "UTF-8");
writer.println(env.get("Path"));
writer.close();
Process process = probuilder.start();
// I have stream readers and such here, but not to bore you with that!
// Wait to get exit value
int exitValue = process.waitFor();
System.out.println("\n\nExit Value is " + exitValue);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
When I run this jar file independently on the server, it does its job correctly. Though when I perform a commit (hence triggering a post-commit event) the jar does not run. I have done the following to help work out the problem:
- Checked the .jar is being referenced correctly in the post-commit.bat file by changing the directory to a non-existent one (J:\Users\Nick\Devel........\post_commit_hook.jar). I get an error client side showing the following: (Warning: post-commit failed on exit code 1, unable to access jarfile)
Client-side Commit Response (Eclipse)
So this seems to indicate to me that the post-commit script is referencing the .jar file and knows what to do with it? As when it references the file correctly (C:\Users...) there's no error...
- I have checked that both 'VisualSVNServer Admins' and NETWORK-SERVICE have permission to execute the .jar:
The permissions are in place...
- I am aware that there may be PATH environment issues, and so I have included code in the JAR file to print the variable... But this doesn't help if it can't even run under the VisualSVN hook!
I have spent days on this issue and am getting nowhere close to a solution, having scoured various forums and not found anything that works :(
I hope someone can help me with this!