Post-receive in Windows---git hooks trigger Jenkins to build Artifcat

Source: Internet
Author: User
Tags git hooks

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.