Python Example

Top  Previous  Next

This is an example IronPython script that can be tested outside of FinalBuilder Server using the Context.py stub (see Script Based Triggers).

 

import Context

 

#copy from here

 

from System import DateTime

 

def TriggerTest():

 app = 'cmd.exe'

 wd = r'C:\Windows\System32'

 

 if Context.ComparisonDateTime <  DateTime.Now.AddMinutes(-30):

         result = Context.ExecuteProgram(app, wd, '/c "echo hi"')

         if result.ExitCode == 0:        

                 Context.SetTriggered()

                 Context.AddTriggerOutputMessage('%s successful, build will be triggered' % app)                        

         else:

                 print 'Build will not be triggered'

                 print '%s failed with return codee %d: %s ' % (app, result.ExitCode, result.StdError)

 else:

         print 'Build has been run in the last 30 minutes - not running'

                 

TriggerTest()

 

#copy to here

 

print Context.Output()

 

 

Things to note:

Only the code between the copy from/copy to comments would be copied to the Trigger script
You can import modules, such as time. To do this you will need to specify the install directory of Iron Python
you can use sys.path.append() to add any other directories from which you would like to import modules
'print' statements from the last run will appear under the Script area of the trigger