post-receive in Windows---git hooks trigger Jenkins to build artifcat

來源:互聯網
上載者:User

標籤:

  如何在Windows上編寫post-receive,當git使用者push檔案到git server時。檢查commit message,如果包含RUN_BUILD就調用Jenkins build API編譯項目。

環境設定:

1. 安裝Jenkins ---流行的代碼管理工具

選擇Remote trigger scripts 在Jenkins Job build 配置項。

2. 安裝scm-manager ---同時支援svn,git...

3. 安裝git-client---需要用到git command

4. 安裝wget command---訪問URL in command

把post-receive.bat放在git hooks目錄下。

 1 @ echo off 2 set CI_JOB_NAME=CI-Test 3 set JENKINS_BUILD_API=http://localhost:8080/job/%CI_JOB_NAME%/build?token=BUILD //set yourself token value in jenkins config page. 4 ::read post-receive stdin parmameters 5 set /p OLDREV_NEWREV_REFNAME= 6 set OLDREV=%OLDREV_NEWREV_REFNAME:~0,40% 7 set NEWREV=%OLDREV_NEWREV_REFNAME:~41,40% 8 set REFNAME=%OLDREV_NEWREV_REFNAME:~82,999% 9 10 11 set MESSAGE_FILE_TEMP=%CI_JOB_NAME%_COMMIT_MSG_TEMP.txt12 ::Get commit message and retrive RUN_BUILD snippt13 git log --pretty^=format:%%s %OLDREV%..%NEWREV% >%MESSAGE_FILE_TEMP% 14 15 16 findstr /c:RUN_BUILD %MESSAGE_FILE_TEMP%17 if %ERRORLEVEL% == 0 (18 "C:\Program Files (x86)\GnuWin32\bin\wget.exe" ^19     --header="Content-Type:text/plain;charset=UTF-8" ^20     --output-document="-" ^21     --timeout=2 ^22     --auth-no-challenge ^23     --user=Jenkins User ^24     --password=Jenkins password^25     %JENKINS_BUILD_API% >NUL 2>$1) 26 del %MESSAGE_FILE_TEMP%

當push code到git server時就會觸發Jenkins 編譯項目。

post-receive in Windows---git hooks trigger Jenkins to build artifcat

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.