我們正在使用 Google Cloud Build 構建一個用 Java 撰寫的 Spring Boot 應用程式。但是,我們有一個私有的 Maven 存盤庫(如果需要,托管在 Artifact Registry 上),除非應用程式有權訪問此存盤庫,否則它不會構建。
該cloudbuild.yaml
檔案如下所示:
steps:
- name: maven:3.8.6-eclipse-temurin-17-alpine
entrypoint: mvn
args: [ 'clean', 'verify', '-Dmaven.test.skip=true' ]
通常,我將私有 Maven 存盤庫的憑據添加到~/.m2/settings.xml
檔案中。
在使用 Google Cloud Build 構建專案時,向 Maven 授予對私有 Maven 代碼庫的訪問權限的推薦方法是什么?
uj5u.com熱心網友回復:
在運行 maven 步驟之前,您可以在 Google Cloud Build中創建一個額外的步驟來生成憑據并將它們存盤在檔案 ( ) 中:~/.m2/settings.xml
###### previous Cloud Build Steps ###
- name: 'bash'
args: ['./cloudbuild_credentials.sh'] ### <--- script to generate creds
dir: 'src' ### <--- directory might be different
id: 'generate-credentials'
env:
- PRIVATE_REPO_PASS=$_PRIVATE_REPO_PASS ### <--- keys might be passed to Cloud Build via Triggers
###### next Cloud Build Steps ###
cloudbuild_credentials.sh
腳本 ( ) 的外觀示例(生成并保存~/.m2/settings.xml
包含敏感資料的檔案):
printf '
<settings>
<servers>
<server>
<id>private-repo</id>
<username>xyz</username>
<password>%s</password>
</server>
</servers>
</settings>
' "${PRIVATE_REPO_PASS}" > ~/.m2/settings2.xml
這樣,您只將非敏感資料提交到 repo,并從外部傳遞密鑰。例如通過Google Cloud Build Triggers。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/507970.html
標籤:Google Cloud Collective 行家 谷歌云构建
上一篇:獲取所有標簽黃瓜的串列
下一篇:在com.google.api-client:google-api-client-android:2.0.0中找不到AbstractGoogleClientRequest和GoogleClientRe