John Joseph
John Joseph

Reputation: 951

Git + Jenkins Builds from hooks - remote branches across multiple servers

I'm not 100% sure what best practice is in my situation and whether I have the hooks set up in the wrong place.

My architecture/workflow is as follows (simplified):

Git Repos - //SERVER-NAME/e$/repositories/PROJECT-NAME

I then have two remote branches on their own servers:

DEV - //DEV-SERVER/e$/projects/PROJECT-NAME
UAT - //UAT-SERVER/e$/projects/PROJECT-NAME

So, let's assume work is done directly on the DEV server. when done and committed, I want that commit to trigger a build from the DEV branch on the same server (Jenkins is running on the DEV and UAT servers).

In the Configure section of jenkins, I have the Git Repos URL above in the 'Repository URL' section and 'DEV' in the 'Branches to build'.

in the checked out/cloned DEV branch, I have a post-commit hook with the following content:

#!/bin/sh
curl http://localhost:8080/job/PROJECT-NAME/build?delay=0sec

However, this is presumably checking out/cloning the remote DEV branch which has not yet received the committed changes? I then tried changing the hook to 'post-receive' thinking this would be triggered after a

git push origin DEV

but this didn't trigger.

I then thought that the hook might need to sit within the actual remote repositories' hooks directory, but I'm not sure if A) this is correct and if so B) what the hook should contain - presumably a URL that kicks off the build on the DEV server?

Bit confused ...

Also, I'd like the same to work on the UAT server. I'd like the workflow to be

  1. Commit on DEV
  2. Triggers a build on DEV (incl unit tests etc)
  3. Merge DEV with UAT
  4. Triggers a build on UAT
  5. Merge UAT with master
  6. Tag created and released to live.

I'm not sure if the above workflow would be better as only running the build on the UAT server upon a git merge into master (but BEFORE it merges, only merging on successful build) ?

Thanks ..

Upvotes: 2

Views: 425

Answers (1)

joran
joran

Reputation: 2883

From my comment: A post-receive hook is a remote server hook, so it should be located in the hooks directory of your remote server (//SERVER-NAME/e$/repositories/PROJECT-NAME). The pushed commits should be available on remote server when this hook is triggerd.

What's the best workflow for your project depends on so manny things, if you have one that works go with that and adjust it, or try another way of doing things, when it start to itch to much.

An alternative workflow in this case could be to have Jenkins polling your repo on remote server for new commits:

  1. Jenkins pools DEV branch and new commits triggers a build job (and test)
  2. On success Jenkins push DEV branch to UAT branch
  3. Jenkins pools UAT branch and new commits triggers a build job
  4. On success Jenkins push UAT branch to master
  5. Jenkins pools master and new commits triggers a job that tags and releases to live

You may have requirements that this workflow does not satisfy, such as publishing all commits in the main repo, pushing to a development server before it should be available for UAT.

Upvotes: 1

Related Questions