iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 30
0
Microsoft Azure

Azure 的自我修煉系列 第 30

Day30 使用 Jenkins 系統來部署 Azure

使用 Jenkins 系統 部署 Azure

上一篇我們創建了 Jenkins 系統,
接下來我們要用 Jenkins 來部署專案到 Azure 服務。

在 Jenkins 設定 Azure 插件與環境

教學課程:使用 Azure VM 代理程式調整 Jenkins 部署

安裝 Azure VM 代理程式外掛程式

點選 "管理Jenkins"
https://ithelp.ithome.com.tw/upload/images/20200930/20072651iSgmUlnpB9.png

點選 "管理外掛程式"
https://ithelp.ithome.com.tw/upload/images/20200930/20072651Y0iqKWoLrV.png

輸入 "Azure VM",勾選 "Azure VM Agents",點擊直接安裝
https://ithelp.ithome.com.tw/upload/images/20200930/20072651vbOcwm01mr.png

等待安裝完成,點擊回首頁
https://ithelp.ithome.com.tw/upload/images/20200930/20072651zMCvhQlByi.png

設定 Azure VM 代理程式外掛程式

點選 "管理 Jenkins",點選 "設定系統"
https://ithelp.ithome.com.tw/upload/images/20200930/2007265104dicneGrH.png

設定系統最下面有 "Cloud" ,點選 "a separate configuration page"
https://ithelp.ithome.com.tw/upload/images/20200930/20072651iNEbuyYrBE.png

點選新增雲, 選擇 "Microsfot Azure Agents"
https://ithelp.ithome.com.tw/upload/images/20200930/20072651dK0h2JysxM.png

進入設定頁面
https://ithelp.ithome.com.tw/upload/images/20200930/20072651ixLJWLMOXA.png

建立 Active Directory 服務主體

az ad sp create-for-rbac --name jenkins_sp

https://ithelp.ithome.com.tw/upload/images/20200930/200726513VWMswSROd.png

az account list

https://ithelp.ithome.com.tw/upload/images/20200930/20072651B9pEQvtdwg.png

點擊 "Azure Credentials"
https://ithelp.ithome.com.tw/upload/images/20200930/20072651RME65duPMJ.png

填入驗證資料
https://ithelp.ithome.com.tw/upload/images/20200930/20072651Gnj9eTiega.png

輸入資源群組名稱 myJenkinsAgentGroup
https://ithelp.ithome.com.tw/upload/images/20200930/20072651WA1ZqBcGL5.png

設定代理程式資源

遇到問題,感覺是外掛問題!
https://ithelp.ithome.com.tw/upload/images/20200930/20072651OwOdC6t0rm.png

使用 Azure Cli 來部署

登入 Jenkins 伺服器

ssh azureuser@<ip_address>

https://ithelp.ithome.com.tw/upload/images/20200930/20072651slk6iB9WMb.png

安裝 Azure cli

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

https://ithelp.ithome.com.tw/upload/images/20200930/20072651XODZc1w2Oo.png

且換到 Jinkins 帳號

sudo su - jenkins

登入 az cli

az login

https://ithelp.ithome.com.tw/upload/images/20200930/20072651OLnQsadGJq.png
取得URL與驗證碼

使用瀏覽器開啟 https://microsoft.com/devicelogin
輸入驗證碼
https://ithelp.ithome.com.tw/upload/images/20200930/20072651rSBRGffEM1.png

登入 Azure 帳號
https://ithelp.ithome.com.tw/upload/images/20200930/20072651JAkNpBsWZb.png

登入完成
https://ithelp.ithome.com.tw/upload/images/20200930/200726513Vi7VuAmyg.png

回到 Terminal 發現也登入完成
https://ithelp.ithome.com.tw/upload/images/20200930/200726510xB4VtJDQF.png

驗證登入

az group list --query '[].name'

https://ithelp.ithome.com.tw/upload/images/20200930/2007265191yxJTWkm4.png

創建任務

點擊新增任務
https://ithelp.ithome.com.tw/upload/images/20200930/20072651UYbhxa3kxY.png

輸入任務名稱
https://ithelp.ithome.com.tw/upload/images/20200930/20072651SPH7VPmcBH.png

測試 az cli 指令
建置 - 新增 shell 步驟 - 輸入 "az group list",
https://ithelp.ithome.com.tw/upload/images/20200930/20072651XQjaOJX9gq.png

儲存後點選 "馬上建置",
https://ithelp.ithome.com.tw/upload/images/20200930/20072651Za1kWZuRA2.png

下方會有建置歷程,在時間朋友有三角形,點選三角形會有 "console output"
https://ithelp.ithome.com.tw/upload/images/20200930/20072651uZ0zW2gIgS.png

點擊 "console output",會看到建置的動作
https://ithelp.ithome.com.tw/upload/images/20200930/200726510rFjZJoZtS.png

看到 az group list 的輸出內容,代表 az cli 指令可以正常使用,
接下來就是看專案的CI/CD步驟要怎麼設計嚕!

參賽心得

哇~我終於完賽了,連續寫 30 天文章真的是個大挑戰,
每天寫到快12點,趕在最後半小時送出,真的是汗顏!
剛開賽前幾天還可以進度超前,儲存了好幾天的文章,
但是過了15號之後,技術儲備開始不夠用了XD,
開始邊學邊打心得,趕在結束前擠出東西來,
但是真的學習到很多,也更暸解Azure平台,
但是完成的那一剎那,真的是滿滿的感動,
尤其是第一篇有全部三十天的文章連結,
看到自己生命的軌跡。

在15號之後,很多人都趕在參賽最後一天開始,
覺得很好玩,感覺 Deadline 要交作業了,才開始動XD,
然後看別人的文章,有很多人都是非常認真的在寫,
看到有興趣的就訂閱起來,這些人每天都會寫優質的文章,
也激勵我自己努力寫完最後的15天,
感謝自己,也感謝IT邦舉辦鐵人賽,更感謝一起參賽的鐵人友們,
一起努力完成鐵人賽嚕!

相關連結:

上一篇 Day29 Azure 平台架設 Jenkins 系統
第一篇 Day01 Azure 的自我修煉


上一篇
Day29 Azure 平台架設 Jenkins 系統
系列文
Azure 的自我修煉30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 則留言

0
我思故我在
iT邦研究生 2 級 ‧ 2020-10-01 12:51:01

恭喜!

pellok iT邦新手 3 級 ‧ 2020-10-05 10:40:39 檢舉

謝謝你

0
暐翰
iT邦大師 1 級 ‧ 2020-10-01 12:52:19

恭喜大大完賽!
30天內容很精彩!

pellok iT邦新手 3 級 ‧ 2020-10-05 10:41:35 檢舉

感謝暐翰,你的文章也很精彩,一起加油!

我要留言

立即登入留言