I want to trigger a Jenkins job after a new branch has been created and then populated via a push.
For example I would do something like this:
git checkout -b jdd_debug_branch_create_a
git push --set-upstream origin jdd_debug_branch_create_a
On the Jenkins server I see the following json snippet being delivered via a push event from a GitHub generic web hook.
{
"ref":"refs/heads/jdd_debug_branch_create_a",
"before":"0000000000000000000000000000000000000000",
"after":"b3df70cf4ac43b37b69c36560487d3aaaa352580"
}
Is it reasonable to assume a push event where the before ref is all zero's and the after ref is non-zero would be the first time a push to this new branch has occurred?
If not is there an other way to detect when the first push to new branch is made?
CodePudding user response:
Yes: this is described in the githooks documentation (which needs some work):
... where <old-value> is the old object name stored in the ref, <new-value> is the new object name to be stored in the ref and <ref-name> is the full name of the ref. When creating a new ref, <old-value> is the all-zeroes object name.
The same general rules apply for deletion, where the new value will be the all-zeros object.
Note that just because some ref (branch or tag name) is being created now does not mean that the commit or commits identified by that ref and its predecessors are themselves new. With your example, for instance, jdd_debug_branch_create_a
probably identifies the same commit as some existing branch name.