' Perforce P4search Trigger Script for Windows
'
' DISCLAIMER
' -----------
'
' User contributed content on the Perforce Public Depot is not supported
' by Perforce, although it may be supported by its author. This applies
' to all contributions even those submitted by Perforce employees.
'
' If you have any comments or need any help with the content of this
' particular folder, please contact support@perforce.com, and I will try
' to help.
'
' This script is meant to be called from a Perforce trigger.
' It should be placed on the Perforce Server machine.
' See usage information below for more details.
'
' NOTE:
' You must set your SEARCH_HOST below (including http://)
' You must set your SEARCH_TOKEN below
' You must set your CURL_EXE location
' You must set the SEARCH_LOG location
' You should place this script in a path that does not include spaces.
'
' Prerequisites:
' 1. curl. curl can be downloaded from
' http://curl.haxx.se/download.html.
'
' TEST PLAN
'
' 1. Verify that script name prints out correctly
' 2. Dies without type and value arguments
' 3. Dies if unknown arguments
' 4. Dies if SEARCH_HOST is still default
' 5. Dies is SEARCH_TOKEN is still default
' 6. Calls out to curl in background and returns immediately
' 7. Logs error if curl fails
' 8. Successfully notifies P4search if curl succeeds
' 9. Repeat 5&6&7 when run as trigger
SEARCH_HOST = "http://my-P4search-host:8088"
SEARCH_TOKEN = "MY-UUID-STYLE-TOKEN"
SEARCH_MAXTIME = 10
SEARCH_LOG = "c:\temp\P4search.log"
CURL_EXE = "c:\windows\system32\curl.exe"
' DO NOT EDIT PAST THIS LINE ---------------------------------------
' Determine name and full path of the script
Myname = Wscript.ScriptName
Fullname = Wscript.ScriptFullName
' Parse arguments
Ttype = WScript.Arguments.Named.Item("type")
Tvalue = WScript.Arguments.Named.Item("value")
' Check arguments
If WScript.Arguments.Count <> 2 Then
Wscript.Echo "Unexpected arguments"
Usage Myname,Fullname
End If
If Ttype = "" Then
Wscript.Echo "No event type supplied"
Usage Myname,Fullname
End If
If Tvalue = "" Then
Wscript.Echo "No value supplied"
Usage Myname,Fullname
End If
If SEARCH_HOST = "" Then
Wscript.Echo "SEARCH_HOST empty or default; please update in this script"
Usage Myname,Fullname
End If
If SEARCH_HOST = "http://my-P4search-host:8088" Then
Wscript.Echo "SEARCH_HOST empty or default; please update in this script"
Usage Myname,Fullname
End If
If SEARCH_TOKEN = "" Then
Wscript.Echo "SEARCH_TOKEN empty or default; please update in this script"
Usage Myname,Fullname
End If
If SEARCH_TOKEN = "MY-UUID-STYLE-TOKEN" Then
Wscript.Echo "SEARCH_TOKEN empty or default; please update in this script"
Usage Myname,Fullname
End If
SEARCH_QUEUE = SEARCH_HOST & "/api/queue/" & SEARCH_TOKEN
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run CURL_EXE & " --output " & SEARCH_LOG & " --stderr " & SEARCH_LOG & " --max-time " & SEARCH_MAXTIME & " --data " & Ttype & "," & Tvalue & " " & SEARCH_QUEUE, 0
Wscript.Quit 0
Sub Usage(aname,afullname)
Wscript.Echo "Usage: cscript " & aname & " /type:<type> /value:<value>"
Wscript.Echo " /type: specify the event type (e.g. job, shelve, commit) "
Wscript.Echo " /value: specify the ID value "
Wscript.Echo ". "
Wscript.Echo " This script is meant to be called from a Perforce trigger. "
Wscript.Echo " It should be placed on the Perforce Server machine and the "
Wscript.Echo " following entries should be added using 'p4 triggers': "
Wscript.Echo ". "
Wscript.Echo " P4search.change form-commit change ""C:\windows\system32\cscript.EXE /nologo %quote%" & afullname & "%quote% /type:change /value:%formname%"" "
Wscript.Echo " P4search.commit change-commit //... ""C:\windows\system32\cscript.EXE /nologo %quote%" & afullname & "%quote% /type:commit /value:%change%"" "
Wscript.Echo ". "
Wscript.Echo " Please note that the use of '%quote%' is not supported on 2010.2 servers (they are harmless"
Wscript.Echo " though); if you're using this version, ensure you don't have any spaces in the pathname to"
Wscript.Echo " this script."
Wscript.Echo ". "
Wscript.Echo " Be sure to modify the SEARCH_HOST and SEARCH_TOKEN variable in this script as appropriate. "
Wscript.Echo " The SEARCH_TOKEN must match the searchEngineToken in your p4search.config file. "
Wscript.Quit 99
End Sub