[英]Google Cloud Build loses ability to authenticate with my private GitHub repository
[英]Access to private Maven Repository from Google Cloud Build?
我們正在使用 Google Cloud Build 構建 Spring 引導應用程序,該應用程序用 Java 編寫。 但是,我們有一個私有的 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 存儲庫?
在運行 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 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.