I’m trying to use cfexecute to run a powershell file that does a git pull to refresh itself. Poor man’s CD using gitlab webhook because I can’t get a git runner to do it. It appears that nothing is happening because nothing ends up in the log file and the site isn’t changing. Any suggestions?

	function refreshSite(event, rc, prc){
cfexecute(name='C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe', arguments='-File c:\dev\thcguard\refreshSite.ps1', outputfile='c:\dev\thcguard\refreshsite.log');
event.setView('main/refreshSite');
}


Interestingly the log is being created, it’s just empty…

Try specifying the errorFile in cfexecute, you might get some more info in there.

Also powershell has some security restrictions in place by default that will prevent it from running unsigned scripts. Take a look at

I wouldn’t necessarily recommend you disable that feature on a server.

You might be better off just create a bat file in this case, or what I have done is have the webhook just write a file, then have another process (eg windows task scheduler) running that looks for the file and performs the action. This way you can give less permission to the CFML server.

Pete Freitag
Foundeo Inc.

Thanks for responding. I got further with a batch file. It can’t find the reference to git.exe from the execution context, though. Any ideas on how to call it so it will just do a git pull into the repository folder to which I originally cloned it?

From the bat file you should be able to do

cd c:\path\to\repository\
c:\path\to\git.exe pull origin master


I’ve tried everything I can think of and it just hangs now No error output or log output. Server is still processing requests to different urls. This is the latest attempt:

 	function refreshSite(event, rc, prc){
cfexecute(name='C:\Program Files\Git\cmd\git.exe', arguments='--git-dir=c:\dev\thcguard\.git pull origin development', outputfile='c:\dev\refreshsite.log', errorfile='c:\dev\error.log');
event.setView('main/refreshSite');
}


The bat file was hanging too, even with /C as the first parameter.

If you don’t supply a timeout, you’ll never see the results…

That is very useful information! I hope they fix that soon or at least add that info to the docs.

Unfortunately it just times out no matter how long I set the timeout.

I’m just going to go with @pfreitag suggestion and use the windows task scheduler. No point in even adding the webhook. I hate the lack of elegance, and the 5 minute delay between checks, but I need to make some progress. ACF is better for some things I guess.

Chances are the process has paused for user input, which means it will hang forever since cfexecute doesn’t expose an input stream for you to pipe any input. Try running the same process from the command line as the same user CF is to see what it does. It may be prompting for Git credentials.

For what it’s worth, there is also a Java library called JGit which has a java-based implementation of a Git client. I used it in CommandBox.

1 Like

Thank you. I’ll look into jgit.

It’s not waiting for user input - I can run the batch file manually with no problem. I finally got something working by using watchDirectory (great program btw) to run the batch file when it sees a change in a file, which I trigger by using a webhook that does fileWrite(). What a kludge But it works.