Jenkins 簡單部署

Gary Ng
4 min readMay 17, 2024

--

假如是 mac 的用戶可以使用 brew 進行 jenkins 的安裝,指令如下:

brew install jenkins

這邊建議 mac 的用戶在使用 brew install 可以搭配HOMEBREW_NO_AUTO_UPDATE=1 , 否則每次執行 brew install 都會更新套件花費許多時間。

等到安裝完畢後即可進入 jeknins , 預設網址如下:

http://localhost:8080/

ps: jenkins admin 密碼位置

<home>/.jenkins/secrets/initialAdminPassword

之後 jenkins 一些資料的位置就是會儲存在 <home>./jenkins 這個路徑底下。

以下我們撰寫一個簡單的 repository 並且搭配 jenkins 進行部署, repository 內容如下:

version: "3.1"

services:
gatus:
image: twinproduction/gatus
container_name: gatus
volumes:
- ./config:/data/config
ports:
- 8081:8080
environment:
- GATUS_CONFIG_PATH=/data/config

config 檔案內容如下

endpoints:
- name: website # Name of your endpoint, can be anything
url: "https://twin.sh/health"
interval: 5s # Duration to wait between every status check (default: 60s)
conditions:
- "[STATUS] == 200" # Status must be 200
- "[BODY].status == UP" # The json path "$.status" must be equal to UP
- "[RESPONSE_TIME] < 1000" # Response time must be under 300ms

設置好 repoistory 後我們在 jenkins 加上我們的 repo。

注意: 記得在 repo 上設定 jenksfile

pipeline {
agent any

stages {
stage("Build") {
steps {
echo "Building"
}
}

stage("Test") {
steps {
echo "Testing"
}
}
}
}

首先點選 new item

2. 因為我們的範例要創建多分支的 pipeline 因此點選 multibranch

3. 設置 git credentials

設定完後我們就可以來 build 了

--

--

Gary Ng
Gary Ng

Written by Gary Ng

軟體工程師、後端工程師

No responses yet