Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save chaitu6022/f8bf278c8dc34b29a28b to your computer and use it in GitHub Desktop.

Select an option

Save chaitu6022/f8bf278c8dc34b29a28b to your computer and use it in GitHub Desktop.

Revisions

  1. @marten-cz marten-cz created this gist Apr 4, 2013.
    26 changes: 26 additions & 0 deletions githook-postreceive-jenkins.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/bin/bash

    REPO="My-Job-Name"
    TOKEN="token from jenkins"
    JENKINSURL="http://login:[email protected]/"

    declare -A branches

    while read oldrev newrew ref; do
    if [ -z $ref ]; then
    ref=$newrev
    newrev=""
    fi

    echo "$oldrev $newrev $ref" >> /var/log/githook/githook.log

    if [ "${ref:0:11}" = "refs/heads/" ]; then
    branch=${ref:11}
    branches["${branch}"]="${branch}"
    fi
    done

    for branch in "${branches[@]}"; do
    echo "Project ${REPO} building ${branch}" >> /var/log/githook/git-post-receive.log
    curl -o /tmp/aaa.tmp --silent "${JENKINSURL}/job/${REPO}/buildWithParameters?token=${TOKEN}&cause=GIT+push&BRANCH=${branch}" >> /var/log/githook/git-post-receive.log
    done