Skip to content

Instantly share code, notes, and snippets.

@chinghwayu
Created January 12, 2017 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chinghwayu/277a2e6845187819898235b13d5c871d to your computer and use it in GitHub Desktop.
Save chinghwayu/277a2e6845187819898235b13d5c871d to your computer and use it in GitHub Desktop.
' Perforce Jenkins Trigger Script
'
' 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.
'
' Adapted from swarm-trigger.vbs
'
'
' Prerequisites:
' 1. curl. curl can be downloaded from
' http://curl.haxx.se/download.html.
'
JENKINS_HOST = "https://My-Jenkins-Server:8080/"
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
Tvalue = WScript.Arguments.Named.Item("value")
' Check arguments
If WScript.Arguments.Count <> 1 Then
Wscript.Echo "Unexpected arguments"
Usage Myname,Fullname
End If
If Tvalue = "" Then
Wscript.Echo "No value supplied"
Usage Myname,Fullname
End If
If JENKINS_HOST = "" Then
Wscript.Echo "JENKINS_HOST empty or default; please update in this script"
Usage Myname,Fullname
End If
Set WshShell = WScript.CreateObject("WScript.Shell")
DoubleQuote = chr(34)
WshShell.Run DoubleQuote & CURL_EXE & DoubleQuote & " --header ""Content-Type: application/json"" --request POST --data ""payload={change:" & Tvalue & ", p4port:\""My-Perforce-Server:1666\""}"" https://My-Jenkins-Server:8080/p4/change", 0
Wscript.Quit 0
Sub Usage(aname,afullname)
Wscript.Echo "Usage: cscript " & aname & " /value:<value>"
Wscript.Echo " /value: specify the changelist "
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 " perforce.commit change-commit //... ""C:\windows\system32\cscript.EXE /nologo %quote%" & afullname & "%quote% /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.Quit 99
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment