# Cài đặt Jenkins Master trên Docker

Jenkins này được cài đặt trên Docker trên server XPEnology.

### Step 1: Cài đặt Jenkins.

Lần 1 mình có cài trực tiếp thông qua Container Manager trên DSM nhưng sau khi cài xong không thể truy cập đến Container đang chạy.

Lần 2 cài thông qua lệnh docker run sau đây  
`<span class="editor-theme-code">docker run \</span>`  
`<span class="editor-theme-code">  --name Jenkins-Controller \</span>`  
`<span class="editor-theme-code">  --detach \</span>`  
**`<strong class="editor-theme-bold editor-theme-code">--volume /volume1/docker/Jenkins:/var/jenkins \</strong>`**  
`<span class="editor-theme-code">  --publish 8080:8080 \</span>`  
`<span class="editor-theme-code">--publish 50000:50000 \</span>`  
`<span class="editor-theme-code">  jenkins/jenkins:lts-jdk21</span>`

**Đặc biệt**, dòng lệnh “`<span class="editor-theme-code">--volume /volume1/docker/Jenkins:/var/jenkins \</span>`<span style="white-space: pre-wrap;">” dùng để ánh xạ thư mục host và container. Đảm bảo mọi dữ liệu của Jenkins được lưu trữ vào thư mục </span>`<span class="editor-theme-code">/volume1/docker/Jenkins</span>`<span style="white-space: pre-wrap;"> trên DSM và sẽ không bị mất đi khi container dừng hoặc xoá.</span>

### Step 2: Cài đặt Plugin

<span style="white-space: pre-wrap;">Tại đây do chưa tìm hiểu được để cấu hình CI/CD cho Unity cần những plugin nào nên mình chọn </span>**“Install suggested plugins”**.

Các plugin cần thiết có thể cài đặt sau.

Đã cài thêm  
<span style="white-space: pre-wrap;">– </span>**Blue Ocean:**<span style="white-space: pre-wrap;"> Một giao diện hiện đại, trực quan, giúp dễ dàng quản lý và sử dụng Jenkins</span>  
<span style="white-space: pre-wrap;">– </span>**Email Extension:**<span style="white-space: pre-wrap;"> Gửi email thông báo.</span>  
<span style="white-space: pre-wrap;">– </span>**Discord Notify:**<span style="white-space: pre-wrap;"> Gửi thông báo qua discord.</span>

### Step 3: Cài đặt Jenkins URL

Tạo chứng chỉ SSL  
<span style="white-space: pre-wrap;">– Trên DSM truy cập </span>**Control Panel -&gt; Security -&gt; Certificate.**  
<span style="white-space: pre-wrap;">– Tạo một Certificate mới với domain name là tên miền muốn tạo certificate (ở đây là </span>`<span class="editor-theme-code">jenkins.thanhdv.com</span>`).

<span style="white-space: pre-wrap;">Tạo Reverse Proxy để xử lý truy cập. Cho phép truy cập qua </span>`<span class="editor-theme-code">jenkins.thanhdv.com</span>`<span style="white-space: pre-wrap;"> thay vì </span>`<span class="editor-theme-code">thanhdv.com:8080</span>`  
<span style="white-space: pre-wrap;">– Trên DSM truy cập </span>**Control Panel -&gt; Login Portal -&gt; Advanced -&gt; Reverse Proxy**<span style="white-space: pre-wrap;"> và tạo mới.</span>  
– General:  
\+ Description: Đặt tên gợi nhớ, mô tả (ở đây mình đặt là Jenkins)  
– Source (Setup cho truy cập từ bên ngoài)  
\+ Protocol: HTTPS  
\+ Hostname: jenkins.thanhdv.com  
\+ Port: 443  
\+ Enable HSTS: Bật để tăng bảo mật.  
– Destination  
\+ Protocol: HTTP (vì Jenkins trong docker đang chạy HTTP)  
\+ Hostname: localhost  
\+ Port: 8080 (8080 là mặc định. Nếu thay bằng port được setup trong lúc cài đặt Container).

Gán chứng chỉ cho Reverse Proxy  
<span style="white-space: pre-wrap;">– Quay lại </span>**Control Panel -&gt; Security -&gt; Certificate.**  
– Config chứng chỉ jenkins.thanhdv.com đã tạo ở trên cho dịch vụ jenkins.thanhdv.com.

<span style="white-space: pre-wrap;">Điền </span>`<span class="editor-theme-code">https://jenkins.thanhdv.com</span>`<span style="white-space: pre-wrap;"> vào </span>**Jenkins URL**<span style="white-space: pre-wrap;"> nếu đang trong quá trình cài đặt ban đầu hoặc truy cập </span>**Manage Jenkins -&gt; System -&gt; Jenkins Location -&gt; Jenkins URL**