我正在测试gitlab ci / cd,并尝试构建一个已签名的APK,但我的 脚本失败。我应该更改或添加什么?
我添加了变量KEYSTORE_FILE,KEYSTORE_PASSWORD,KEY_ALIAS,KEY_PASSWORD 带有值。
assembleRelease:
stage: release
script:
- echo $KEYSTORE_FILE | base64 -d > my.keystore
- ./gradlew assembleRelease
-Pandroid.injected.signing.store.file=$(pwd)/my.keystore
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD
-Pandroid.injected.signing.key.alias=$KEY_ALIAS
-Pandroid.injected.signing.key.password=$KEY_PASSWORD
artifacts:
paths:
- app/build/outputs/apk/release
错误:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:packageRelease'.
1 exception was raised by workers:
java.lang.RuntimeException:
com.android.ide.common.signing.KeytoolException: Failed to read key from
store "/builds/juantamad.02072019/2019_samplebuild/my.keystore": null
但是应该成功
答案 0 :(得分:1)
假设您有正确的缩进(如前所述,它们不是),则问题可能是由多行命令引起的-它仅首先执行- ./gradlew assembleRelease
,而没有其他参数
要包装长行,可以使用YAML多行字符串:
script:
- ...
- >
./gradlew assembleRelease
-Pandroid.injected.signing.store.file=$(pwd)/my.keystore
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD
-Pandroid.injected.signing.key.alias=$KEY_ALIAS
-Pandroid.injected.signing.key.password=$KEY_PASSWORD
了解更多:
-
另一个可能的原因-如果您的环境变量在项目设置中设置为受保护的,
并且您正在不受保护的分支中工作。
然后var不会传递给您的工作