本頁面中的部分或全部資訊可能不適用於 Trusted Cloud by S3NS。
在 Cloud Code for IntelliJ 中在本機開發服務
使用 Cloud Code,您可以在類似 Cloud Run 的環境中,於本機開發 Cloud Run 服務。Cloud Code 會監控來源的變更,並快速更新執行中的服務,以反映這些變更。
定義執行設定
執行服務前,您必須建立執行設定:
- 前往導覽列中的「Run/Debug configurations」選取器,然後按一下「Edit Configurations」。
- 在 Cloud Code:Cloud Run 下方,選擇「Cloud Run: Run Locally」(Cloud Run:在本機執行)。
- 如要讓 Cloud Code 在儲存變更後自動重新部署應用程式,請在「Watch mode - rebuild and redeploy」(監看模式 - 重建並重新部署) 下選取「On file save」(儲存檔案時)。新的 Cloud Run 服務預設會選取「隨選」。如要進一步瞭解手錶模式,請參閱「手錶模式」。
指定建構工具選項和相關設定。
Cloud Code 支援 Docker、Jib 和 Buildpacks 構件類型。
按一下 [確定]。
選用:自訂設定
在本機開發時,選擇「編輯設定」後,即可使用「進階修訂版本設定」部分,指定服務帳戶、環境變數和 SQL 連線 (使用 Cloud Run (全代管) 時) 等其他設定。
環境變數
系統會自動將下列環境變數新增至執行中的容器:
名稱
|
說明 |
範例
|
PORT
|
HTTP 伺服器應監聽的通訊埠。
|
8080
|
K_SERVICE
|
要執行的 Cloud Run 服務名稱。
|
hello-world
|
K_REVISION
|
正在執行的 Cloud Run 修訂版本名稱。
|
hello-world.1
|
K_CONFIGURATION
|
建立修訂版本的 Cloud Run 設定名稱。
|
hello-world
|
儲存密鑰
如果程式碼包含 API 金鑰、密碼和憑證等可能具有機密性的資料,建議您將這些資料儲存為密鑰。透過 Cloud Code,您可以將這些密鑰安全地儲存在 Secret Manager 中,並在需要時以程式輔助方式擷取。如要詳細瞭解如何使用 Cloud Code 建立及管理密鑰,請參閱 Secret Manager 指南。
執行服務
如要執行服務,請按照下列步驟操作:
- 從導覽列的「Run/Debug configurations」選取器中,選擇「Cloud Run: Run Locally」執行目標。
- 按一下「Cloud Run: Run Locally」(Cloud Run:在本機執行)
。
- 查看執行中服務的記錄,直接串流至輸出視窗。
部署完成後,您可以按照「事件記錄」面板中顯示的網址,查看正在執行的服務。在下方範例中,這個網址是 http://localhost:8080。

取得支援
如要在 IntelliJ IDE 中提供意見回饋或回報問題,請依序前往「Tools」
>「Cloud Code」
>「Help / About」
>「Submit feedback or report an issue」
,在
GitHub 回報問題。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-11 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-11 (世界標準時間)。"],[[["Cloud Code enables local development of Cloud Run services in a simulated environment, with real-time updates reflecting code changes."],["Before running a service, users must define a run configuration in the \"Edit Configurations\" section, specifying options like the builder type and watch mode preference."],["During local development, users can customize configurations by adding settings such as service accounts, environment variables, and SQL connections."],["Cloud Code automatically adds environment variables like PORT, K_SERVICE, K_REVISION, and K_CONFIGURATION to running containers."],["Secrets, such as API keys and passwords, can be securely stored in Secret Manager and accessed programmatically using Cloud Code."]]],[]]