目標:gitlab配置webhook鉤子,push代碼時觸發webhook,向node服務器發送任務,node服務器down代碼,執行打包和檢測,結束後觸發gitlab發郵件。node
步驟:
1.進入gitlab,找到本身的項目,查看是否有權限設置,而後設置:
(Settings -> Integrations)git
URL:http://nodeServerIp:8080/webhook
Secret Token: ABCDEFG // 觸發請求的認證碼,避免DOS攻擊
Trigger:
勾選Push events選項
勾選Merge request events選項
點擊「Add web hook」web
2.Setting --> General --> Visibility, project features, permissions --> 點擊Expand --> 打開Pipelines(Build, test, and deploy your changes)--> Save Changes服務器
3.Settings -> CI /CD --> Pipeline triggers --> Expand
在展開的輸入框中輸入「ci 」,點擊「Add trigger」, 而後將生成的Token字段複製出來。curl
4.在項目根目錄添加.gitlab-ci.yml文件,文件內容以下:gitlab
stages: - ci # 定義 job build: stage: ci script: - curl http://nodeServerIp:8080/downGitlabCiShApi > gitlab-ci.sh - chmod 751 ./gitlab-ci.sh - ./gitlab-ci.sh