$ mkdir trader-stable.git $ cd trader-stable.git $ git init --bare Initialized empty Git repository in /Users/Shared/trader-stable.git/ $
Configuring automatic push by successfully build
TweetPosted on Sunday Mar 01, 2015 at 11:19PM in Jenkins
Making Jenkins to push to an another remote repository if build finishes successfully.
Recipe
-
Create a bare repository
-
Click
Add Repository
-
Enter
Repository URL
-
Click
Advanced…
-
Enter
stable
toName
-
Click
Add post-build action
⇒Git Publisher
-
Check
Push Only If Build Succeeds
-
Click
Add Tag
-
Enter
$BUILD_NUMBER
toTag to push
-
Check
Create new tag
-
Enter
stable
toTarget remote name
-
Click
Save
Test
$ pwd /Users/kyle/tmp/trader $ echo 'push if succeeds test' >> hi.txt $ git commit -am 'push if succeeds test' $ git push origin master
Jenkins said Pushing tag 8 to repo stable
$ git remote add stable /Users/Shared/trader-stable.git $ git fetch stable remote: Counting objects: 1, done. remote: Total 1 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (1/1), done. From /Users/Shared/trader-stable * [new tag] 8 -> 8 $
Configuring automatic build by push for git repository
TweetPosted on Sunday Mar 01, 2015 at 07:15PM in Jenkins
We can start the build by send request to following URL.
http://YOURHOST/jenkins/job/PROJECTNAME/build
Recipe
In my case, Jenkins is deployed in /
, and the server is running on port 18080
. so the command to start a build of the job named trader
will be:
curl http://localhost:18080/job/trader/build
So put following shell script into $ORIGIN_BARE_REPOSITORY/hooks/post-receive
and execute chmod +x post-receive
.
#!/bin/sh curl http://localhost:18080/job/trader/build
Testing
Push some modification as follows:
$ echo hook test >> hi.txt $ git add hi.txt $ git commit -m 'hook test' $ git push origin master
Check the build was run automatically as expected, and the output.
Creating a simplest Jenkins job against a git repository
TweetPosted on Sunday Mar 01, 2015 at 05:45PM in Jenkins
-
Click
New Item
-
Enter
trader
inItem name
and selectBuild a free-style software project
-
Select
Git
and enterRepository URL
-
Click
Add build step
-Execute shell
-
Enter
cat hi.txt
intoCommand
-
Click
Save
-
Click
Build Now
-
Click a Build History which just created by build
-
Click
Console Output