【问题标题】:Access to private Maven Repository from Google Cloud Build?从 Google Cloud Build 访问私有 Maven 存储库?
【发布时间】:2022-09-13 20:41:34
【问题描述】:

我们正在使用 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 存储库的访问权限的推荐方法是什么?

    标签: maven google-cloud-build


    【解决方案1】:

    在运行 maven 步骤之前,您可以创建一个额外的 step in 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。

    【讨论】:

      猜你喜欢
      • 2020-10-08
      • 1970-01-01
      • 2017-04-17
      • 1970-01-01
      • 2019-07-18
      • 2018-09-23
      • 2018-11-27
      • 2022-01-14
      • 2020-05-18
      相关资源
      最近更新 更多