VisualSVN 提交后挂钩与批处理文件

发布于 2024-09-07 10:05:53 字数 574 浏览 8 评论 0原文

我在 Windows 服务器上运行 VisualSVN。

我正在尝试添加一个提交后挂钩,以便在提交发生时更新我们的暂存项目。

在 VisualSVN 中,如果我在挂钩/提交后对话框中键入命令,一切都会很好。

但是,如果我使用完全相同的命令创建批处理文件,则会收到一条错误,指出提交后挂钩失败。没有其他信息。

我的命令使用绝对路径。

我尝试将批处理文件放入 VisualSVN/bin 目录中,但出现相同的错误。

我已确保 VisualSVN 具有批处理文件所在目录的权限。

我唯一能想到的是我没有从 VisualSVN 正确调用它。我只是用批处理文件名(“c:\VisualSVN\bin\my-batch-file.bat”)替换钩子/提交后对话框中的 svn update 命令,我已经尝试过使用和不使用路径(如果没有路径,它根本找不到该文件)。

我是否需要在 SVNCommit 对话框中使用不同的语法来调用批处理文件?在批处理文件中怎么样(它只有我的 svn update 命令。如果我从命令行运行批处理文件,它就可以工作。)

最终我想使用批处理文件,因为我想在提交后做更多的事情。

I'm running VisualSVN on a Windows server.

I'm trying to add a post-commit hook to update our staging project whenever a commit happens.

In VisualSVN, if I type the command in the hook/post-commit dialog, everything works great.

However, if I make a batch file with the exact same command, I get an error that says the post-commit hook has failed. There is no additional information.

My command uses absolute paths.

I've tried putting the batch file in the VisualSVN/bin directory, I get the same error there.

I've made sure VisualSVN has permissions for the directories where the batch file is.

The only thing I can think of is I'm not calling it correctly from VisualSVN. I'm just replacing the svn update command in the hook/post-commit dialog with the batch file name ("c:\VisualSVN\bin\my-batch-file.bat") I've tried it with and without the path (without the path it doesn't find the file at all).

Do I need to use a different syntax in the SVNCommit dialog to call the batch file? What about within the batch file (It just has my svn update command. It works if I run the batch file from the command line.)

Ultimately I want to use a batch file because I want to do a few more things after the commit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦明 2024-09-14 10:05:53

使用 VisualSVN 时>选择存储库 >属性>挂钩>提交后挂钩。
我用于发送电子邮件然后运行脚本的代码在哪里,其中包含我想要自定义的命令

 "%VISUALSVN_SERVER%\bin\VisualSVNServerHooks.exe" ^
    commit-notification "%1" -r %2 ^
    --from [email protected] --to "[email protected]" ^
    --smtp-server mail.domainname.com ^
    --no-diffs ^
    --detailed-subject
    --no-html

set PWSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
%PWSH% -command $input ^| C:\ServerScripts\SVNScripts\post-commit-wp.ps1 %1 %2
if errorlevel 1 exit %errorlevel%

脚本文件位于 C:\ServerScripts\SVNScripts\
post-commit-wp.ps1 和我传入两个 VisualSVN 变量作为 %1 和 %2

  • %1 = serverpathwithrep
  • %2 = 修订号

该脚本文件是用 Windows PowerShell 编写的,

# PATH TO SVN.EXE
$svn = "C:\Program Files\VisualSVN Server\bin\svn.exe"
$pathtowebistesWP = "c:\websites-wp\"

# STORE HOOK ARGUMENTS INTO FRIENDLY NAMES
$serverpathwithrep = $args[0]
$revision   = $args[1]

# GET DIR NAME ONLY FROM REPO-PATH STRING 
# EXAMPLE: C:\REPOSITORIES\DEVHOOKTEST
# RETURNS 'DEVHOOKTEST'
$dirname = ($serverpathwithrep -split '\\')[-1]

# Combine ServerPath with Dir name
$exportpath = -join($pathtowebistesWP, $dirname);

# BUILD URL TO REPOSITORY
$urepos = $serverpathwithrep -replace "\\", "/"
$url = "file:///$urepos/"


# --------------------------------
# SOME TESTING SCRIPTS
# --------------------------------

# STRING BUILDER PATH + DIRNAME
$name = -join($pathtowebistesWP, "testscript.txt");
# CREATE FILE ON SERVER
New-Item $name -ItemType file
# APPEND TEXT TO FILE
Add-Content $name $pathtowebistesWP
Add-Content $name $exportpath

# --------------------------------


# DO EXPORT REPOSITORY REVISION $REVISION TO THE ExportPath
&"$svn" export -r $revision --force "$url" $exportpath

我添加了注释来解释每一行及其作用。简而言之,脚本:

  • 获取所有参数
  • 构建本地目录路径
  • 运行 SVN 导出
  • 将文件放置到网站/发布目录。

这是将新提交的代码部署到网站的简单方法。

When using VisualSVN > Select the Repo > Properties > Hooks > Post-commit hook.
Where is the code I use for Sending an Email then running a script, which has commands I want to customize

 "%VISUALSVN_SERVER%\bin\VisualSVNServerHooks.exe" ^
    commit-notification "%1" -r %2 ^
    --from [email protected] --to "[email protected]" ^
    --smtp-server mail.domainname.com ^
    --no-diffs ^
    --detailed-subject
    --no-html

set PWSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
%PWSH% -command $input ^| C:\ServerScripts\SVNScripts\post-commit-wp.ps1 %1 %2
if errorlevel 1 exit %errorlevel%

The script file is located on C:\ServerScripts\SVNScripts\
post-commit-wp.ps1 and I pass in two VisualSVN variables as %1 and %2

  • %1 = serverpathwithrep
  • %2 = revision number

The script file is written in Windows PowerShell

# PATH TO SVN.EXE
$svn = "C:\Program Files\VisualSVN Server\bin\svn.exe"
$pathtowebistesWP = "c:\websites-wp\"

# STORE HOOK ARGUMENTS INTO FRIENDLY NAMES
$serverpathwithrep = $args[0]
$revision   = $args[1]

# GET DIR NAME ONLY FROM REPO-PATH STRING 
# EXAMPLE: C:\REPOSITORIES\DEVHOOKTEST
# RETURNS 'DEVHOOKTEST'
$dirname = ($serverpathwithrep -split '\\')[-1]

# Combine ServerPath with Dir name
$exportpath = -join($pathtowebistesWP, $dirname);

# BUILD URL TO REPOSITORY
$urepos = $serverpathwithrep -replace "\\", "/"
$url = "file:///$urepos/"


# --------------------------------
# SOME TESTING SCRIPTS
# --------------------------------

# STRING BUILDER PATH + DIRNAME
$name = -join($pathtowebistesWP, "testscript.txt");
# CREATE FILE ON SERVER
New-Item $name -ItemType file
# APPEND TEXT TO FILE
Add-Content $name $pathtowebistesWP
Add-Content $name $exportpath

# --------------------------------


# DO EXPORT REPOSITORY REVISION $REVISION TO THE ExportPath
&"$svn" export -r $revision --force "$url" $exportpath

I added comments to explain each line and what it does. In a nutshell, the scripts:

  • Gets all the parameters
  • Build a local dir path
  • Runs SVN export
  • Places files to a website/publish directory.

Its a simple way of Deploying your newly committed code to a website.

携君以终年 2024-09-14 10:05:53

您是否尝试使用“call”命令执行批处理文件?我是说:

call C:\Script\myscript.bat

Did you try to execute batch file using 'call' command? I mean:

call C:\Script\myscript.bat
把时间冻结 2024-09-14 10:05:53

我正在尝试同样的事情,发现你还必须在 hooks 文件夹中包含脚本..bat 文件。

I was trying the same thing and found that you also must have the script in the hooks folder.. the bat file that is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文