Jenkins 取得建置後的產物
學習目的
延續透過 Docker 建立 JenkinsAgent後續的學習,在完成Jenkins Node的佈局後,接下來學習如何取得建置完成的產物。
目錄
一、前言
在專案建置完成後如果想要取得對應的產出物,透過master和agent要如何取得檔案,方法有很多種這邊選擇一個較簡易上手的方式,當然如果建置環境本身不是隨機銷毀的(指定docker image運行後關閉),也可以直接訪問環境來取得檔案。
二、實作步驟
以下建置用專案會使用官網提供的simple-node-js-react-npm-app來進行
套件安裝
這邊要安裝Copy Artifact Plugin這個套件來協助,這邊就不在教學直接附上安裝完成的結果圖:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
節點分佈
針對節點我們把master多開一個作業排程,主要用來複製建置完的檔案使用。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
新增作業
這邊會建立兩個作業,一個用來建置另一個用來將檔案複製出來
Build 作業
專案這邊我們使用simple-node-js-react-npm-app
來進行,這邊就直接貼上各樣設定
原始碼管理
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
建置環境
不知道怎麼執行nodejs可以參考再 Jenkins 底下執行 NodeJs
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Build Steps
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
複製檔案作業
此作業我們指定Master來當作執行的node
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
接著設定建置觸發,使Build專案建置完成後自己觸發複製流程
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
複製流程設定
此選項就是安裝Copy Artifact Plugin套件所提供的功能,相關設定可以如下:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- project name:從哪個專案過來
- Which build:哪個建置流程
- Artifacts to copy:要複製的路徑(可以檔名、*.副檔名或資料夾路徑)
- Artifacts not to copy:不要複製的
- Target directory:儲存目標
基本上設定就完成了!!
三、進行測試
直接點選Build作業流程進行測試即可
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
左下角也會出現運行中的提示
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
如果有設定完成CopyFile會自動進行作業
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
確認作業完成後可以進入建置細節查複製出來的相關檔案
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
四、檔案檢查
範例是使用docker建立起來的,有對應資料夾出來我們到相對應的路徑就可以看到複製出來的檔案了
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
結論
Jenkins是一個很靈活使用工具,此範例是直接取得檔案之後再來進行佈署,此外Jenkins能進行的佈署方式還有很多種,不過這一塊就等之後有需求再來研究了,基本上越來越熟悉後會發現Jenkins能做到的事情真的很多,要建置CI/CD的客製化的程度也十分的高。
相關參考來源:
[DevOps] Jenkins copy artifact Plugin 分享