Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 钻头铲斗至ColdFusion柱钩_Git_Coldfusion_Bitbucket_Coldfusion 9 - Fatal编程技术网

Git 钻头铲斗至ColdFusion柱钩

Git 钻头铲斗至ColdFusion柱钩,git,coldfusion,bitbucket,coldfusion-9,Git,Coldfusion,Bitbucket,Coldfusion 9,我的公司开始使用Bitbucket来托管我们的Git回购,我还没有找到任何好的例子来说明如何正确设置.cfm文件,以便POST钩子调用并自动获取和签出。.cfm文件能够解析有效负载,但不能执行命令。如有任何帮助或示例/指南链接,将不胜感激 服务器:安装了Git并运行Adobe CF9和IIS 7的Windows Server 2003 R2 代码示例: <cfset strRepositoryDirectory = "Z:\web\_repositories\someproject.git

我的公司开始使用Bitbucket来托管我们的Git回购,我还没有找到任何好的例子来说明如何正确设置.cfm文件,以便POST钩子调用并自动获取和签出。.cfm文件能够解析有效负载,但不能执行命令。如有任何帮助或示例/指南链接,将不胜感激

服务器:安装了Git并运行Adobe CF9和IIS 7的Windows Server 2003 R2

代码示例:

<cfset strRepositoryDirectory = "Z:\web\_repositories\someproject.git"> <!--- The full windows directory path to the GIT repository. --->
<cfset strExecutablePath = '"C:\Program Files (x86)\Git\bin\sh.exe" --login -i'>
<cfset strWebsiteRootDirectory = "Z:\web\someproject"> <!--- The full windows directory path to the website root. --->
<cfset strGitBinPath = "git"> <!--- The full windows directory path to the GIT bin folder. --->
<cfset strBranch = ""> <!--- The branch that was updated in the repository. --->

<cfset jsonPayload = "">

<cfset arrCommits = ArrayNew( 1 )>

<cfset boolUpdate = false> <!--- Flag that determines if script should update the website contents. --->

<!--- Parse the POST data and convert to a structure. --->
<cfif IsDefined( getHTTPRequestData().content )>
  <cfset jsonPayLoad = toString( getHTTPRequestData().content )>
  <cfset jsonPayLoad = ReplaceNoCase( jsonPayLoad, "payload=", "", "ALL" )>
  <cfset jsonPayLoad = URLDecode( jsonPayLoad )>
  <cfset jsonPayLoad = DeserializeJSON( jsonPayLoad )>

  <!--- Grab the commits, if any. --->
  <cfset arrCommits = StructFind( jsonPayLoad, "commits" )>

  <!--- Check the commits. --->
  <cfif ArrayLen( arrCommits ) EQ 0>
    <cfset boolUpdate = true>
  <cfelse>
    <cfloop array = "#arrCommits#" index = "idxCommit">
      <cfset strBranch = StructFind( idxCommit, "branch" )>

      <cfif UCase( strBranch ) EQ "DEVELOPMENT">
        <cfset boolUpdate = true>

        <cfbreak>
      </cfif>
    </cfloop>
  </cfif>
</cfif>

<!--- Check to see if the website content should be updated. --->
<cfif boolUpdate>
  <cfexecute name = "#strExecutablePath#" arguments = 'cd "#strRepositoryDirectory#" && #strGitBinPath# fetch'></cfexecute>
  <cfexecute name = "#strExecutablePath#" arguments = 'cd "#strRepositoryDirectory#" && GIT_WORK_TREE="#strWebsiteRootDirectory#" #strGitBinPath# checkout -f'></cfexecute>

  <cffile action = "append" file = "#ExpandPath('.')#\deploy.log" output = "#DateFormat( NOW(), 'yyyy-mm-dd' )# #TimeFormat( NOW(), "long" )# -- Deployed branch: #strBranch# || Commit: Automatic PUSH from Bitbucket." addnewline = "yes">
</cfif>

最好的办法是设置一个.bat文件,您可以使用
cfexecute
运行该文件,而不是进行大量的
cfexecute
调用。然后需要确保分配给ColdFusion服务器的用户可以运行该.bat文件。我通常以CF用户的身份登录服务器,并通过
cmd.exe
直接运行批处理文件,以确保所有内容都已正确配置,并且我拥有执行所有需要运行的内容的正确权限