Gateway Update event - execute .bat file

Anyone knows how to find the name of the project that is currently being saved.

I am trying to run a git autocommit script on a single project.

Not currently possible, unfortunately - although improving the project update script is on our (short) list of improvements.

Im getting crazy here. My .bat works when I:

  1. run the .bat file direcly from win explorer
  2. from cmd (32)
  3. from cmd(64) ( a bit different syntax here)

I can verify that the script runs by using a logger:
image
And yeah, it runs twice, why?

I have stripped it down so path variables should not matter. Anyone know why github is not updating when saving project?
git-auto-commit.bat:

@echo off
for /F "tokens=2" %%i in ('date /t') do set mydate=%%i
set mytime=%time%
::echo Current time is %date%:%mytime%

cd "C:\Program Files\Inductive Automation\Ignition\data\projects\myProject"
cmd /c ""C:\Program Files (x86)\Git\cmd\git.exe" add ."
cmd /c ""C:\Program Files (x86)\Git\cmd\git.exe" commit -m "Designer save @ %date%:%mytime%""
cmd /c ""C:\Program Files (x86)\Git\cmd\git.exe" push origin"

Update script:

logger = system.util.getLogger("SF_GW_UpdateScript")
logger.info("Running git update!")
import time
time.sleep(5)
system.util.execute(["C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.bat"])

One thing to consider is that in some odd cases time.sleep raises a java.lang.IllegalArgumentException as experienced by me.

So for your script it would be something like this:

logger = system.util.getLogger("SF_GW_UpdateScript")
logger.info("Running git update!")
from java.lang import Thread
Thread.sleep(5000)
system.util.execute(["C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.bat"])

Reference:

I really appreciate the input, unfortunately it did not fix my problem.

logger = system.util.getLogger("SF_GW_UpdateScript")
logger.info("Running git update!")
#import time
#time.sleep(5)
from java.lang import Thread
Thread.sleep(5000)
system.util.execute(["C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.bat"])
logger.info("Done exec git update!")

Yielded the same result :
image
But no update on git.

Anyone know how to monitor the bat file in windows logs somehow?

I have now included logging of the bat file (in the beginning of the file):

@echo off
set LOGFILE=batch.log
call :LOG > %LOGFILE%
exit /B
:LOG

The log file does not even get created when supposedly started from Ignition. When running the bat file manually, it always get created.

Tips anyone?

Two ideas:

  • Python uses backslash as the escape character. Try changing them to forward slashes in your script.

  • If the batch file needs elevated privileges to run, make a shortcut with “Run as Administrator” checked, then run the shortcut from your script.

Thx Jordan,
Back slashes is actually correct.

I think I found out the main problem.

  1. Ignition runs under the system account. And the system account does not have access to the SSH keys.
  2. The SSH keys were created with ssh-keygen in git-bash, using the administrator account.

If i open a client locally, my script (see below) actually works now. Due to the client beeing launched under with the same user as the SSH key.

I have tried to copy the keys to the system account with various methods, but the battle was to mighty, and such I ran from the battlefield.

Here is a working script that can be put under gateway update event, where no .bat file is needed. But for windows the SSH key issue needs sorting out…

Im moving the gateway to linux just because of this problem! Another very annoying issue, is that git log display the commit as successful. I guess the logs get created before the authenitcation is checked.

logger = system.util.getLogger("GW_UpdateScript")
logger.info("Running git update!")
path="C:\Program Files\Inductive Automation\Ignition\data\projects\myProject"
import time
try:
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","config","--global","user.name","'myname"])
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","config","--global","user.email","myemail@fml.com"])
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","-C",path,"add","."])
	time.sleep(5)
	dateStr=str(system.date.now())
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","-C",path,"commit","-m","Designer save @ "+dateStr])
	time.sleep(5)
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","-C",path,"push"])
	logger.info("git update done!")
except Exception as e:
	logger.infof("error, errorMsg: \n",e)