使用 circleci cli 進行本機端測試

Paul Tang
3 min readFeb 16, 2020

--

公司目前使用的 CI/CD 工具是 CircleCI,常常在撰寫 CI 腳本的時候,都會有一個小小的麻煩就是

要一直推 Github 測試也太煩了吧

沒錯,如果只是為了測試 CI 腳本就要一直推一些沒有意義的東西,那真的是太蠢了XD

經過一番搜尋,發現了一個好用的工具 circleci cli 命令列,是原廠提供的工具,連結在此

安裝方式也相當簡單,如果是 MacOS & homebrew 的使用者,只要簡單的用brew 安裝即可

brew install circleci

安裝好以後,測試看看

Usage:
circleci [command]
Available Commands:
config Operate on build config files
diagnostic Check the status of your CircleCI CLI.
help Help about any command
local Debug jobs on the local machine
namespace Operate on namespaces
orb Operate on orbs
setup Setup the CLI with your credentials
update Update the tool to the latest version
version Display version information
Flags:
-h, --help help for circleci
--host string URL to your CircleCI host, also CIRCLECI_CLI_HOST (default "https://circleci.com")
--token string your token for using CircleCI, also CIRCLECI_CLI_TOKEN
Use "circleci [command] --help" for more information about a command.

看得到這些基本上就是安裝完成了。

裡面有一些滿神奇的功能,不過礙於版面,我這邊只介紹我常用的兩個功能,剩下的可以看上方連結的官方文件喔。

1. circleci config validate

當你辛辛苦苦的寫完 CI 腳本,一定希望可以在本機端測試(家醜不外揚),此時只要用

circleci config validate

就可以進行本機端的 validation,如果有基本的語法錯誤可以在此時被檢查出來

2. circleci local execute

因為 circleci 的原理就是使用 docker container 乾淨的環境進行 testing & building,因此我們當然希望可以完全模擬那樣的環境,此時我們就可以使用

circleci local execute

他就會完全地在本機端跑 .circle/config 的腳本內容囉!

以上

--

--

Paul Tang
Paul Tang

Written by Paul Tang

初來乍到,剛到東京的菜鳥後端工程師,希望有一天能成為獨當一面的Full Stack Hacker

No responses yet