Jenkins配合webhook實現push,自動構建併發送郵件

Jenkins

  1. 安裝java8 jdk

    sudo apt-get update
    sudo apt-get install openjdk-8-jdkgit
    
  2. 安裝jenkins

    sudo apt-get update
    sudo apt-get install jenkins
    

    問題:

    1. 在ubuntu 18.04上測試發現。使用官網linux ununtu安裝方法安裝之後。啓動jenkins成功,並且開啓防火牆以及阿里雲安全組也配置了8080端口。任然無法通過ip:8080訪問jenkins

      解決:卸載重新安裝

      • 卸載

        # 服務
        sudo apt-get remove jenkins
        # 安裝包,注意這裏如果不是ubuntu那就yum
        sudo apt-get remove --auto-remove jenkins
        # 配置和數據
        sudo apt-get purge jenkins
        sudo apt-get purge --auto-remove jenkins
        
      • apt-get直接安裝,不配置其他內容

        sudo apt-get install jenkins

  3. 啓動jenkins

    sudo systemctl start jenkins
    或
    sudo /etc/init.d/jenkins [start|restart|stop]
    
    • 當遇到Job for jenkins.service failed because the control process exited with error code.報錯,運行systemctl status jenkins.service查看詳細報錯內容
  4. jenkins配置修改

    vim /etc/default/jenkins

  5. jenkins初始密碼文件地址

    /var/lib/jenkins/secrets/initialAdminPassword

  6. jenkins插件安裝速度慢

    1. jenkins輸入密碼之後頁面一直加載(被牆)https://www.cnblogs.com/yoyoketang/p/12115432.html

      按照以上方法並未找到文件。

      • 輸入ip:8080/pluginManager/advanced
      • 修改Update Site爲http://mirror.xmission.com/jenkins/updates/update-center.json
      • 點擊submit之後,重啓jenkins服務
    2. 更改下載源https://cloud.tencent.com/developer/article/1563303

      • vim /var/lib/jenkins/updates/default.json
      • 輸入:,然後輸入1,$s/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g
      • 再輸入1,$s/http:\/\/www.google.com/https:\/\/www.baidu.com/g
      • 保存退出:wq
      • 重啓jenkins服務
  7. jenkins漢化

    1. http://ip:8080/pluginManager/available安裝locale和Localization: Chinese (Simplified)插件
    2. 重啓服務
  8. Jenkins 拉取git代碼失敗

    確認是否添加git憑據

插件

pipeline

在這裏插入圖片描述

有多種類型,多分支流水線gitHub Organization可以讀取項目中Jenkinsfile執行構建,其餘均需手動加入構建

例子

w
  1. 使用github webhooks觸發腳本自動構建

    在jenkins上設置好身份驗證令牌之後,在github-》setteing-》webhook中設置

在這裏插入圖片描述

  1. 發送郵件

    • Manage jenkins -> configure system -> jenkins location設置郵箱,不設置,會出現問題2中場景

    • 本文用qq郵箱,需開啓qq郵箱smtp,詳情請google

    • Manage jenkins -> configure system->Extended E-mail Notification設置smtp信息
      在這裏插入圖片描述

      • 注意打開 Allow sending to unregistered users,否則會出現問題1場景
      • 某些情況還需配置郵件通知(使用默認郵件通知)
      • 測試郵箱是否可以發送成功
      • 在項目的配置中選擇editable email notification,配置發送郵箱
        在這裏插入圖片描述

問題

  1. Not sending mail to unregistered user [email protected] because your SCM claimed this was associated with a user ID ‘xxx’ which your security realm does not recognize; you may need changes in your SCM plugin

    Stack Overflow

  2. Failed to send to email(測試郵件是否可以成功發送的時候,一直報錯Can’t send command to SMTP host)

    manage jenkins -> configure system ->jenkins location 設置系統管理員郵箱即可

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