Jenkins搭建前后端分离项目流水线实战
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Jenkins搭建前后端分离项目流水线实战
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                文章目錄
- 項目簡介
 - 流水線建設
 - 前端流水線pipline script
 - nginx配置流水線pipline script
 - 后端流水線pipline script
 - 后端數據庫初始化流水線pipline script
 
項目簡介
飛雪測試平臺是我做的一個Django+Vue前后端分離demo項目。主要用于日志管理,主要是興趣驅動,體驗一下全棧研發。順便記錄一下流水線搭建的一些關鍵代碼。
前端地址:https://github.com/tdx1997tdx/my_tapd_frontend
 后端地址:https://github.com/tdx1997tdx/my_tapd_backend
 demo地址:http://139.198.36.243
流水線建設
對于這個項目建立了4條流水線
 
前端流水線pipline script
pipeline {agent anystages {stage('git clone') {steps {git credentialsId: 'f4209992-d0c8-4f10-bcea-c5edaa0846f1', url: 'https://github.com/tdx1997tdx/my_tapd_frontend.git'}}stage('npm build') {steps {sh 'npm install'sh 'npm run build'}}stage('copy files to nginx') {steps {sh 'rm -rf /usr/local/nginx/html/*'sh 'cp -r ./dist/* /usr/local/nginx/html/'}}} }主要流程就是npm打包出來的產物轉移到nginx上
nginx配置流水線pipline script
pipeline {agent anystages {stage('change_conf') {steps {writeFile encoding: 'utf-8', file: '/usr/local/nginx/conf/nginx.conf', text: ''' worker_processes 1;events {worker_connections 1024; }http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;#gzip on;server {listen 80;server_name 139.198.36.243;location / {root html;index index.html index.htm;}location /api/ {proxy_pass http://127.0.0.1:8080;}} } '''}}stage('restart nginx') {steps {sh 'systemctl restart nginx.service'}}} }對于靜態文件直接獲取,對于后端接口,也就是api開頭的,轉發到8080端口
后端流水線pipline script
pipeline {agent anystages {stage('git pull') {steps {git credentialsId: 'f4209992-d0c8-4f10-bcea-c5edaa0846f1', url: 'https://github.com/tdx1997tdx/my_tapd_backend.git'}}stage('start') {steps {sh 'killall gunicorn || true'sh 'JENKINS_NODE_COOKIE=dontKillMe nohup /usr/local/python3/bin/gunicorn my_tapd_backend.wsgi -w 4 -b 0.0.0.0:8080 &'}}} }后端數據庫初始化流水線pipline script
pipeline {agent anystages {stage('git pull') {steps {git credentialsId: 'f4209992-d0c8-4f10-bcea-c5edaa0846f1', url: 'https://github.com/tdx1997tdx/my_tapd_backend.git'}}stage('migrate') {steps {sh 'pip3 install -r requirements.txt'sh 'python3 manage.py makemigrations'sh 'python3 manage.py migrate'}}} }總結
以上是生活随笔為你收集整理的Jenkins搭建前后端分离项目流水线实战的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: ecshop 2.7.2安装
 - 下一篇: Listener refused the