2023/05/17

Bitbucket Build & Deploy Vue.js Project with Jenkins

 先來Bitbucket找到專案,點擊Repository settings

點選Webhooks


點擊Add Webhooks





輸入http://jenkins-url/bitbucket-hook/
勾選Repo Push

記得開啟Enable History


點擊Jenkins / 管理 Jenkins / 管理外掛程式,新增如下套件
NodeJS Plugin
Bitbucket Plugin

回首頁選擇新增作業,建置 Free-Style 軟體專案

新增Git輸入git https or ssh url,新增Bitbucket SSH private Key


輸入正確會如下圖,沒有任何錯誤提示


將建置觸發程序 / Build when a change is pushed to BitBucket 打勾

打勾Send files or execute commands over SSH after the build runs,點擊Add Server

./test.sh內容如下,記得將權限改為764
#!/bin/bash
cd /var/www/html/test
sudo git pull
sudo npm install && sudp npm run build


打勾Provide Node & npm bin/ folder to PATH

Build Steps貼入下方代碼

#!/bin/bash
npm install -g npm && npm update -g npm
npm install && npm run build


Bitbucket的master分支有被推上來,Bitbucket就會透過Webhooks呼叫Jenkins
Jenkins會自動開始Build,Build完後透過SSH方式執行Server上指令達成Deploy