iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 29
0
Microsoft Azure

Azure 的自我修煉系列 第 29

Day29 Azure 平台架設 Jenkins 系統

Azure 平台架設 Jenkins 系統

Jenkins是一款由Java編寫的開源的持續整合工具,
個人覺方便又好用,
在公司也是使用Jenkins解決煩人的部署問題,
在上次參加的鐵人賽中也要介紹到Jenkins ,可以參考以下兩篇
Day 9 Jenkins CI/CD 伺服器(一)
Day 10 Jenkins CI/CD 伺服器(二)

現在我們在 Azure 上用 Jenkins 服務。

創建 Jenkins 系統

快速入門:使用 Azure CLI 設定 Jenkins

建立虛擬機器

創建 cloud-init-jenkins.txt 檔案
以下腳本是在主機上安裝 Jenkins 系統,並啟動 Jenkins 服務

#cloud-config
package_upgrade: true
runcmd:
  - apt install openjdk-8-jdk -y
  - wget -qO - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
  - sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
  - apt-get update && apt-get install jenkins -y
  - service jenkins restart

使用 az group create 建立資源群組

az group create \
--name QuickstartJenkins-rg \
--location eastus

https://ithelp.ithome.com.tw/upload/images/20200929/20072651ou5pYul8UV.png

創建虛擬機器

查看 az vm 指令

az vm -h

https://ithelp.ithome.com.tw/upload/images/20200929/200726519v4PM05QVN.png
https://ithelp.ithome.com.tw/upload/images/20200929/20072651QZNKROrxyy.png

查看 az vm create 指令

az vm create -h

參數太多,直接從 Examples 開始看XD
https://ithelp.ithome.com.tw/upload/images/20200929/20072651y3NWlev5cB.png
https://ithelp.ithome.com.tw/upload/images/20200929/20072651Ck5GBqY9Rw.png
https://ithelp.ithome.com.tw/upload/images/20200929/2007265114GYCHwEpl.png

由上面的範例暸解各參數的意義
資源群組: QuickstartJenkins-vm
映像檔名稱: UbuntuLTS
管理者名稱: azureuser
--generate-ssh-keys: 產生 SSH-Key
--custom-data: 執行客製化腳本

az vm create \
--resource-group QuickstartJenkins-rg \
--name QuickstartJenkins-vm \
--image UbuntuLTS \
--admin-username "azureuser" \
--generate-ssh-keys \
--custom-data cloud-init-jenkins.txt

https://ithelp.ithome.com.tw/upload/images/20200929/20072651csN3Rrl0M0.png

使用 az vm list 確認新虛擬機器的建立 (和狀態)

az vm list -d -o table --query "[?name=='QuickstartJenkins-vm']" -g QuickstartJenkins-rg

https://ithelp.ithome.com.tw/upload/images/20200929/20072651dJlEuRXCUn.png

請使用 az vm open,在新的虛擬機器上開啟連接埠 8080

az vm open-port \
--resource-group QuickstartJenkins-rg \
--name QuickstartJenkins-vm  \
--port 8080 --priority 1010

https://ithelp.ithome.com.tw/upload/images/20200929/20072651eFpSQVP0Zp.png

設定 Jenkins

使用 az vm show 取得範例虛擬機器的公用 IP 位址

az vm show \
--resource-group QuickstartJenkins-rg \
--name QuickstartJenkins-vm -d \
--query [publicIps] \
--output tsv

https://ithelp.ithome.com.tw/upload/images/20200929/20072651nM3pbFsYwT.png

公用IP 每個VM不一樣,在實作的時候參考自己的VM IP

登入 Jenkins VM

ssh azureuser@<ip_address>

https://ithelp.ithome.com.tw/upload/images/20200929/20072651G2Kau3HcCe.png
https://ithelp.ithome.com.tw/upload/images/20200929/20072651AyzAl5VQck.png

取得 Jenkins 服務的狀態

service jenkins status

https://ithelp.ithome.com.tw/upload/images/20200929/20072651qrcbBXyGqD.png

取得自動產生的 Jenkins 密碼

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

https://ithelp.ithome.com.tw/upload/images/20200929/20072651XeJHQolEAL.png

開啟網頁,輸入密碼
http://<ip_address>:8080
https://ithelp.ithome.com.tw/upload/images/20200929/20072651DZyPyLJaIi.png

再來依據教學安裝套件
https://ithelp.ithome.com.tw/upload/images/20200929/20072651WjtJJixFs9.png
輸入 Create First Admin User

歡迎使用Jenkins! 頁面
https://ithelp.ithome.com.tw/upload/images/20200929/20072651sNMUq0LddA.png

以上動作就完成在 Azure 部署 Jenkins 系統,感覺很簡單XD。

相關連結:

上一篇 Day28 Azure Cache for Redis 服務
下一篇 Day30 使用 Jenkins 系統來部署 Azure


上一篇
Day28 Azure Cache for Redis 服務
下一篇
Day30 使用 Jenkins 系統來部署 Azure
系列文
Azure 的自我修煉30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言