利用git的Hook机制

  1. .git/hooks/pre-push
    1
    2
    3
    #!/bin/bash
    echo ====== trigger jenkins job: maglev-verify in 10s =======
    (sleep 10 && .git/hooks/post-push) &
  2. .git/hooks/post-push
    1
    2
    3
    #!/bin/bash
    branch=$(git rev-parse --abbrev-ref @{upstream})
    curl -k --user ${USER}=${TOKEN} http://${JENKINS_URL}/job/${JOB_NAME}/buildWithParameters --data-urlencode TAG=$branch