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:
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?

@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")"Running git update!")
import time
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")"Running git update!")
from java.lang import Thread
system.util.execute(["C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.bat"])


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

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

Yielded the same result :
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

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")"Running git update!")
path="C:\Program Files\Inductive Automation\Ignition\data\projects\myProject"
import time
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","config","--global","","'myname"])
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","config","--global","",""])
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","-C",path,"add","."])
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","-C",path,"commit","-m","Designer save @ "+dateStr])
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","-C",path,"push"])"git update done!")
except Exception as e:
	logger.infof("error, errorMsg: \n",e)

Thanks @tordvd ! This got us in the right direction. Just a watch out for folks looking to implement on RHEL the standard git version is 1.8 and doesn’t come with the -C option so you’ll need to upgrade to a later version. We also tested implementation with a “Message” gateway event so we could make a portal in the designer for developers to commit and add messages without committing after every single save.

1 Like