How to write post-receive on Windows when git users push files to git server. Check the commit message and call the Jenkins build API to compile the project if it contains Run_build.
Environment settings:
1. Installing Jenkins---Popular code management tools
Select the remote trigger scripts in the Jenkins Job build configuration item.
2. Install Scm-manager---support svn,git ...
3. Install git-client---need to use git command
4. Install wget command---Access URL in command
Put the post-receive.bat in the git hooks directory.
1@Echo off2 SetCi_job_name=ci-test3 Setjenkins_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 parmameters5 Set/P Oldrev_newrev_refname=6 Setoldrev=%oldrev_newrev_refname:~0,40%7 Setnewrev=%oldrev_newrev_refname:~41,40%8 Setrefname=%oldrev_newrev_refname:~82,999%9 Ten One SetMessage_file_temp=%ci_job_name%_commit_msg_temp.txt A ::Get Commit message and retrive run_build snippt -git log--pretty^=format:%%s%oldrev%. %newrev% >%message_file_temp% - the -Findstr/c: Run_build%message_file_temp% - if%ERRORLEVEL% = = 0 ( -"C:\Program Files (x86) \gnuwin32\bin\wget.exe" ^ +--header= "Content-type:text/plain;charset=utf-8" ^ ---output-document= "-" ^ +--timeout=2 ^ A --auth-no-challenge ^ at--user=jenkins User ^ ---password=Jenkins password^ -%jenkins_build_api% >nul 2>$1) - del%message_file_temp%
The Jenkins compilation project is triggered when push code is to git server.
Post-receive in Windows---git hooks trigger Jenkins to build Artifcat