gitã®ç¹å®ãã©ã³ãã¸ã®pushãããã¯ãã¦Jenkinsã¸ã§ããå®è¡ãã
Jenkinsãã©ã°ã¤ã³ã使ãã°è§£æ±ºã§ããããããã©ã社å ç°å¢ã®é½åã§ãã©ã°ã¤ã³ãå ¥ããã®ã大å¤ã ã£ãã®ã§bareã«ããã¯ãä»è¾¼ãã§ã¿ãã
Jenkinsã¸ã§ããç¨æ
ã¸ã§ããä½ãéããã«ãã»ããªã¬ã§ãªã¢ã¼ããããã«ãããã§ãã¯ãã
èªè¨¼ãã¼ã¯ã³ã¯ä»»æã®æååãªã®ã§é©å½ã«
bareãã©ã³ãã«ããã¯ãä»è¾¼ã
ä»åã¯pushãããã¯ãããã®ã§ãupdateããã¯ãä½ã
GIT_DIR/hooks/update.sampleãã»ã¼ä¸¸ã£ã¨ä½¿ããã¦ããããã¨ã«ãã
- ä¾ãã°ãããªæãã§ãcaseæã®ç®æã§developãã©ã³ãã«commitã追å ããããjenkinsã«curlãæãã¦ã¸ã§ããèµ°ããã
- æ¨æºåºåã«åºåãããã®ã¯pushãå©ããã¯ã©ã¤ã¢ã³ãå´ã«è¡¨ç¤ºããã
- Jenkinsã®ã¸ã§ããå®è¡ããURL㯠Jenkins-Host/job/my-job/build?token=æåå
- ã¯ã¨ãªã§ãPOSTã®ããã£ã§ããã
- ãã©ã¡ã¼ã¿ä»ãã§å®è¡ãããªãbuildWithParametersã«ãã¦ãã¯ã¨ãªãããã£ãå¢ãã
#!/bin/sh # --- Command line refname="$1" oldrev="$2" newrev="$3" # --- Safety check if [ -z "$GIT_DIR" ]; then echo "Don't run this script from the command line." >&2 echo " (if you want, you could supply GIT_DIR then run" >&2 echo " $0 <ref> <oldrev> <newrev>)" >&2 exit 1 fi if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then echo "Usage: $0 <ref> <oldrev> <newrev>" >&2 exit 1 fi # --- Check types # if $newrev is 0000...0000, it's a commit to delete a ref. zero="0000000000000000000000000000000000000000" if [ "$newrev" = "$zero" ]; then newrev_type=delete else newrev_type=$(git cat-file -t $newrev) fi case "$refname","$newrev_type" in refs/heads/develop,commit) # execute Jenkins job echo "Automatically execute my-job in jenkins" curl -i -X POST http://Jenkins-Host/jenkins/job/my-job/build?token=520d3a1b13aceb20cf229c1d7f85c4c6 > /dev/null 2>&1 ;; esac # --- Finished exit 0
ããã£ããã¨
update.sampleããã®ã¾ã¾ã³ãã¼ãã¦ãã¯ã©ã¤ã¢ã³ãããpushãå©ãã¨ãããªã¨ã©ã¼ãåºã
*** Project description file hasn't been set
ããã¯update.sampleã®ä¸ã§descriptionãã¡ã¤ã«ã確èªãããããªã³ã¼ããå
¥ã£ã¦ãããã§ã
該å½ç®æãæ¶ãããGIT_DIR/descriptionãç·¨éãã¦é©å½ãªæååã«å¤ãã¦ããã°OK
GIT_DIR/hooks/update.sample 52 # check for no description 53 projectdesc=$(sed -e '1q' "$GIT_DIR/description") 54 case "$projectdesc" in 55 "Unnamed repository"* | "") 56 echo "*** Project description file hasn't been set" >&2 57 exit 1 58 ;; 59 esac