0

post-commit hook.if 파일이 "SOURCE/databasescript"디렉터리에서 커밋되고 파일 이름이 "update.sql"인 jenkins 빌드를 트리거하려고합니다.svn 커밋 된 디렉터리 목록에 파일 이름을 찾는 방법

내가 file.Please 제안 일괄 디렉토리 목록에서 파일 이름을 찾을 조건을 작성하는 방법을 모르는

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 

을 후 커밋합니다. 나를 위해 솔루션 작업 아래

답변

1

:

후 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%" 

후 커밋 후크 젠킨스 - 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