Ôõô²»ÐèÒªÓû§ÃÜÂë¹¹½¨gitlab
ÔÚÈí¼þ¿ª·¢ºÍÐ×÷ÖУ¬gitlabÊÇÒ»¸öºÜÊÇÊܽӴýµÄ´úÂëÖÎÀíƽ̨¡£Í¨¹ýÔÚgitlabÖÐÉèÖÃgit²Ù×÷£¬ÔÚ´úÂëµÄ²î±ðÍ°ÖоÙÐÐÊÂÇ飬ÒÔ¼°ÔÚÐ×÷Àú³ÌÖоÙÐа汾¿ØÖƺÍÐ×÷±äµÃÔ½·¢ÈÝÒס£
È»¶ø£¬ÔÚGitLabÖУ¬Í¨³£ÐèҪΪÿ¸öÓû§ÉèÖÃÓû§ÃûºÍÃÜÂ룬ÒÔ±ã¾ÙÐÐÉí·ÝÑéÖ¤²¢»á¼û´æ´¢¿â¡£¿ÉÊÇ£¬ÓÐʱÄú¿ÉÄÜÏëÒª×èֹǿÖÆÓû§ÊäÈëÃÜÂë¡£ÔÚÕâÖÖÇéÐÎÏ£¬Äú¿ÉÒÔÉèÖÃGitLabÒÔʹ¹¹½¨²»ÐèÒªÓû§ÃÜÂë¡£
½ÓÏÂÀ´£¬ÈÃÎÒÃÇÒ»Æð̽ÌÖÔõÑùͨ¹ý¼òÆӵİ취ʵÏÖ²»ÐèÒªÓû§ÃÜÂëÀ´¹¹½¨GitLab¡£
°ì·¨1£ºÉèÖÃSSHÃÜÔ¿
Ê×ÏÈ£¬ÄúÐèÒªÌìÉúSSHÃÜÔ¿¡£ÈôÊÇÄú»¹Ã»ÓÐÌìÉúSSHÃÜÔ¿£¬ÔòÓ¦¸ÃÊ×ÏÈÌìÉú¡£Äú¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÔÚLinuxϵͳÉÏÌìÉúÃÜÔ¿£º
ssh-keygen -t rsa -C ¡°your_email@example.com¡±
µÇ¼ºó¸´ÖÆ
Ö´ÐдËÏÂÁÌìÉúÒ»¸öеÄSSHÃÜÔ¿¶Ô£¬²¢Ñ¯ÎÊÄúÒªÉúÑĹ«Ô¿ºÍ˽ԿµÄλÖá£
½ÓÏÂÀ´£¬½«¹«Ô¿Ìí¼Óµ½Óû§µÄGitLabÕÊ»§ÖС£ÒªÖ´Ðд˲Ù×÷£¬Çëתµ½GitLabÖеġ°Ð¡ÎÒ˽¼Ò×ÊÁÏÉèÖá±²¿·Ö£¬È»ºóµ¥»÷¡°SSHÃÜÔ¿¡±Ñ¡Ï¡£ÔÚ´Ë´¦£¬Äú¿ÉÒÔ½«¹«Ô¿Ìí¼Óµ½ÄúµÄÕÊ»§ÖС£
°ì·¨2£ºÉèÖÿÍջΪSSH
ÏÖÔÚ£¬ÄúÐèÒª½«´æ´¢¿âÉèÖÃΪʹÓÃSSH¡£Äú¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Íê³É´Ë²Ù×÷£º
git remote set-url origin git@gitlab.example.com:your-username/your-repo.git
µÇ¼ºó¸´ÖÆ
Çë×¢ÖØ£¬´ËÏÂÁî¼Ù¶¨ÄúÒѽ«ËùÓÐÐëÒªÐÅÏ¢Ì滻Ϊ׼ȷµÄÖµ¡£
°ì·¨3£ºÉèÖÃGitLab CI / CD
ÏÖÔÚ£¬ÄúÐèÒªÉèÖÃGitLab CI / CDÒÔ±êʶÄúµÄ´æ´¢¿â¡£Äú¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Íê³É´Ë²Ù×÷£º
variables: GIT_STRATEGY: clone GIT_CHECKOUT: "false" GIT_SUBMODULE_STRATEGY: none GIT_DEPTH: "1"
µÇ¼ºó¸´ÖÆ
Çë×¢ÖØ£¬ÕâÊDZêʶ´æ´¢¿âËùÐèµÄ×îС±äÁ¿¡£Äú»¹¿ÉÒÔƾ֤ÐèÒªÌí¼ÓÆäËû±äÁ¿¡£
°ì·¨4£ºÉèÖÃGitLab Runner
×îºó£¬ÄúÐèÒªÔÚGitLab RunnerÉÏÉèÖÃÄúµÄ¹¹½¨¡£Äú¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Íê³É´Ë²Ù×÷£º
stages: - build variables: GIT_CLEAN_FLAGS: "-ffdx" build: stage: build script: - git clean ${GIT_CLEAN_FLAGS} - git fetch --all - git checkout ${CI_COMMIT_SHA}
µÇ¼ºó¸´ÖÆ
Çë×¢ÖØ£¬ÕâÊDZêʶÔËÐй¹½¨ËùÐèµÄ×îСÉèÖá£Äú»¹¿ÉÒÔƾ֤ÐèÒªÌí¼ÓÆäËû¾ç±¾¡£
½áÂÛ
ͨ¹ý×ñÕÕÕâЩ¼òÆӵİ취£¬Äú¿ÉÒÔÔÚGitLabÖй¹½¨£¬¶øÎÞÐèÇ¿ÖÆÓû§ÊäÈëÃÜÂë¡£Õ⽫ʹ´úÂë¹¹½¨Àú³ÌÔ½·¢¼òÆÓ£¬Ô½·¢Çå¾²£¬²¢ÇÒÄܹ»×ÊÖúÄú¸üºÃµØÖÎÀíÄúµÄ´úÂë¿â¡£
ÒÔÉϾÍÊÇÔõô²»ÐèÒªÓû§ÃÜÂë¹¹½¨gitlabµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡