代码之家  ›  专栏  ›  技术社区  ›  Almund

如何在Gitlab CI for android中管理签名密钥库

  •  2
  • Almund  · 技术社区  · 7 年前

    我最近遇到了Gitlab的奇迹和他们非常好的捆绑CI/CD解决方案。它工作得很好,但是,我们都需要签署我们的二进制文件,不是吗,我没有办法上传一个密钥,因为我会这样做一个詹金斯服务器。

    那么,在构建一个版本时,如果不签入我的密钥和秘密,我怎么能在我的android(实际上是flutter)应用程序上签名呢?

    对于密钥,例如密钥库本身的密码,我发现我可以简单地将它们存储为受保护的变量,但实际的密钥库文件本身除外。我能怎么办?

    任何想法和建议都是非常受欢迎的。 干杯

    2 回复  |  直到 7 年前
        1
  •  9
  •   IvanP    6 年前

    通常我将密钥库文件(base64字符串)、别名和密码存储到Gitlab的secrets变量中。

    在.gitlab-ci.yml中,执行以下操作:

    create_property_files:
      stage: prepare
      only:
        - master
      script:
        - echo $KEYSTORE | base64 -d > my.keystore
        - echo "keystorePath=my.keystore" > signing.properties
        - echo "keystorePassword=$KEYSTORE_PASSWORD" >> signing.properties
        - echo "keyAlias=$ALIAS" >> signing.properties
        - echo "keyPassword=$KEY_PASSWORD" >> signing.properties
      artifacts:
        paths:
          - my.keystore
          - signing.properties
        expire_in: 10 mins
    

    最后,在你的建筑毕业生:

    signingConfigs {
        release {
            file("../signing.properties").with { propFile ->
                if (propFile.canRead()) {
                    def properties = new Properties()
                    properties.load(new FileInputStream(propFile))
    
                    storeFile file(properties['keystorePath'])
                    storePassword properties['keystorePassword']
                    keyAlias properties['keyAlias']
                    keyPassword properties['keyPassword']
                } else {
                    println 'Unable to read signing.properties'
                }
            }
        }
    }
    
        2
  •  1
  •   mmccabe    7 年前

    我用过 git-secret secret/protected environmental variable (如您所知)并修改.gitlab-ci.yml以使用密码打开文件并使用它们。