Question

I'm using post-receive hook in Git server to call a jenkins job. I have a special case where I don't want the jenkins job to be called if the push operation comes from a build machine (which is a git user). Or I don't want the post-receive to be executed if the push has commits that include some specific files (say info.plist). What is the way to approach this problem? I don't want to use git-plugin for jenkins.

Thanks

Was it helpful?

Solution 2

I used git's log to solve the issue. My post-receive script contains a check for an email id. If email id does not belong to build machine then jenkins job is called. We can get email id of the git user who did last commit using git log -1 HEAD --pretty=format:%ae.

OTHER TIPS

The basic idea is to do an early exit 0 (meaning the post-receive reports a success, even though it doesn't call Jenkins) when your conditions are met:

  • if the push operation comes from a build machine

There is no indication of the origin of commits pushed in Git, so your git user on that build machine should leave some clue allowing the upstream hook to identify said commits as coming from said build machine.
It can be a commit message associated to the list of commits you just received.

  • I don't want the post-receive to be executed if the push has commits that include some specific files (say info.plist)

From the previous hook, you can list all the files for each commit received, and test if you see one you don't want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top