【问题标题】:How to find file name exist in svn committed directory list如何在 svn 提交的目录列表中查找文件名
【发布时间】:2018-05-19 07:33:30
【问题描述】:

我想在提交后挂钩中触发 jenkins 构建。如果文件在目录“SOURCE/databasescript”上提交并且文件名为“update.sql”。

提交后

set "REPOS=%~1"
set "TXN=%~3"
set "REV=%~2"
echo "repos %REPOS%." >> C:\test.log
echo "REV %REV%." >> C:\test.log
echo "txn %TXN%." >> C:\test.log
"%VISUALSVN_SERVER%\bin\svnlook.exe" changed -r %2 %1 >>C:\test.log

输出

"repos D:\Repositories\TestNAPFServer." 
"REV 82." 
"txn 81-2e." 
U   SOURCE/databasescript/basedb.sql
U   SOURCE/databasescript/update.sql 

我不知道如何编写条件来查找批处理文件中目录列表中的文件名。请建议。

【问题讨论】:

    标签: batch-file jenkins visualsvn-server svn-hooks post-commit-hook


    【解决方案1】:

    以下解决方案对我有用:

    Post-commit.cmd

    setlocal enabledelayedexpansion
    @echo off 
    REM Get the current path
    set mypath=%cd%
    
    set "REPOS=%~1"
    set "TXN=%~3"
    set "REV=%~2"
    REM create log folder
    IF NOT EXIST %REPOS%\log (
        md %REPOS%\log\
    )
    REM Delete the file log file
    del /F /Q %REPOS%\log\napfposthook.log
    echo "Current path-%mypath%" >> %REPOS%\log\napfposthook.log
    echo "repos %REPOS%." >> %REPOS%\log\napfposthook.log
    echo "REV %REV%." >> %REPOS%\log\napfposthook.log
    echo "txn %TXN%." >> %REPOS%\log\napfposthook.log
    set SVNLOOK="%VISUALSVN_SERVER%\bin\svnlook.exe"
    %SVNLOOK% changed -r %2 %1 >> %REPOS%\log\napfposthook.log
    
    Set SEPARATOR=,
    SET COMMENT=
    
    REM Concatenate all the lines in the commit message
    fOR /F "tokens=2 delims= " %%g IN ('%SVNLOOK% changed -r %REV% %REPOS%') do ( 
        set currentline=%%g
        set COMMENT=!COMMENT!%SEPARATOR%!currentline!
    )
    
    REM Delete the file before insert the directory list
    del /F /Q  %REPOS%\log\napfsearch.txt
    
    REM Write the all directory list into file
    echo %COMMENT% >> %REPOS%\log\napfsearch.txt
    
    REM Find the string into file
    find /I "update.sql" "%REPOS%\log\napfsearch.txt">nul
    set findStatus=%errorlevel%
    echo %findStatus% >> %REPOS%\log\napfposthook.log
    
    
    SET CSCRIPT=%windir%\system32\cscript.exe
    SET VBSCRIPT=D:\Repositories\post-commit-hook-jenkins-sam.vbs
    "%CSCRIPT%" "%VBSCRIPT%" "NAPF_PRODB" "f23338c8b8f7216fad54dd34da7a2a5d" "%findStatus%"
    

    提交后挂钩-jenkins-sam.vbs

    Set args = WScript.Arguments
    JobName = args.Item(0)
    Token = args.Item(1)
    updateDbScript=args.Item(2)
    JenkinsServerUrl="http://10.254.6.206:8080/jenkins/"
    
    If updateDbScript = 0 Then
        Wscript.Echo "Triggered the update job..."
        updateUrl = JenkinsServerUrl+"/buildByToken/buildWithParameters?job=" + JobName + "&token=" + Token+ "&Type=1"
        updateRequest = ""
        'Sending rest request to jenkins 
        HTTPPost updateUrl, updateRequest
    else
         Wscript.Echo "Triggered the jenkins main job..."
         sUrl = JenkinsServerUrl+"/buildByToken/buildWithParameters?job=" + JobName + "&token=" + Token+ "&Type=0"
        'POST Request to send....
        sRequest = ""
        'Sending rest request to jenkins 
        HTTPPost sUrl, sRequest
    End If
    
    
    Function HTTPPost(sUrl, sRequest)
      set oHTTP = CreateObject("Microsoft.XMLHTTP")
      oHTTP.open "POST", sUrl,false
      oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
      oHTTP.setRequestHeader "Content-Length", Len(sRequest)
      oHTTP.send sRequest
      HTTPPost = oHTTP.responseText
     End Function 
    

    【讨论】:

      猜你喜欢
      • 2012-05-06
      • 2011-04-08
      • 2013-10-19
      • 2011-04-26
      • 2011-08-15
      • 1970-01-01
      • 1970-01-01
      • 2012-07-12
      • 1970-01-01
      相关资源
      最近更新 更多