Jenkins 自動部署常見配置方式以及過程

搭建一個jenkins 自動構建工具
https://www.cnblogs.com/loveyouyou616/p/8714544.html
1、弄好機器之間的ssh ,將git 倉庫填入:
在這裏插入圖片描述
2、配置遠程目錄
通常Jenkins 機器和構建的機器是不一樣的,我們需要將Jenkins 的workspace 工程空間下的代碼拉到構建機器上:
點開系統配置 下 SSH Servers 出,新增一個
ssh配置

填寫名稱 機器ip 用戶名,以及目標目錄。點開高級配置填入用戶密碼。
完整如下:
在這裏插入圖片描述

3、 在構建配置中,填入 source files 和remote directory ,已經之後需要執行的命令。
在這裏插入圖片描述

4、自動構建鉤子Generic Webhook Trigger 插件使用(遇坑已解決)
默認認爲你已經安裝好webhook 插件了,安裝之後使用restlet_client 自行模擬觸發請求,正常方式:
http://${ip}/generic-webhook-trigger/invoke 帶上git 的分支信息
在這裏插入圖片描述
在這裏插入圖片描述

使用restlet (谷歌插件模擬測試gitlab發送過來的數據)測試 不是pre_online 分支
在這裏插入圖片描述
是pre_online 分支,triggered 爲true 表明觸發構建
在這裏插入圖片描述

接下來就是在git 參考那裏寫hooks shell 腳本了。(waiting…)

gitlab 那配置webhooks 觸發(每當git push遠程分支的時候)
1、在工程的設置=》 導入所有倉庫 那裏。
2、在Jenkins 裏填上: http://${ip}/generic-webhook-trigger/invoke

在這裏插入圖片描述
3、設置成功之後,會在gitlab底部看到對應的信息。
在這裏插入圖片描述

其實gitlab 觸發之後發送給Jenkins (post json)是類似如下的數據:

{
    "before": "fb32ef5812dc132ece716a05c50c7531c6dc1b4d", 
    "after": "ac63b9ba95191a1bf79d60bc262851a66c12cda1", 
    "ref": "refs/heads/master", 
    "user_name": "123", 
    "user": {
        "email": "[email protected]", 
        "name": "123", 
        "time": "2016-12-09T17:28:02 08:00"
    }, 
    "repository": {
        "name": "webhook", 
        "url": "http://git.oschina.net/oschina/webhook", 
        "description": "", 
        "homepage": "http://git.oschina.net/oschina/webhook"
    }, 
    "commits": [
        {
            "id": "ac63b9ba95191a1bf79d60bc262851a66c12cda1", 
            "message": "1234 bug fix", 
            "timestamp": "2016-12-09T17:28:02 08:00", 
            "url": "http://git.oschina.net/oschina/webhook/commit/ac63b9ba95191a1bf79d60bc262851a66c12cda1", 
            "author": {
                "name": "123", 
                "email": "[email protected]", 
                "time": "2016-12-09T17:28:02 08:00"
            }
        }
    ], 
    "total_commits_count": 1, 
    "commits_more_than_ten": false, 
    "project": {
        "name": "webhook", 
        "path": "webhook", 
        "url": "http://git.oschina.net/oschina/webhook", 
        "git_ssh_url": "[email protected]:oschina/webhook.git", 
        "git_http_url": "https://git.oschina.net/oschina/webhook.git", 
        "git_svn_url": "svn://git.oschina.net/oschina/webhook", 
        "namespace": "oschina", 
        "path_with_namespace": "oschina/webhook", 
        "default_branch": "master"
    }, 
    "hook_name": "push_hooks", 
    "password": "pwd"
}

附上:
常用自動構建腳本

ssh [email protected] &&
cd /data/jenkins/workspace/coinslot_web && cnpm install &&
npm run build &&
tar -zcvf coinslot.tar.gz -C ./dist . &&
scp -r ./coinslot.tar.gz [email protected]:/home/www/web && 
cd /home/www/web && 
tar -zxvf ./coinslot.tar.gz 
rm -rf /home/service/www/web/* &&

參考鏈接:
https://www.cnblogs.com/StitchSun/articles/4712287.html
https://blog.csdn.net/richard_jason/article/details/53188200
https://www.cnblogs.com/kevingrace/p/6479813.html
https://www.cnblogs.com/ceshi2016/p/6529532.html
構建結果通知。
https://www.cnblogs.com/jianxuanbing/p/7211006.html
釘釘通知構建結果
https://www.jianshu.com/p/9e72c79a2f78

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章