3

I'm testing gitlab ci/cd and I'm trying to build a signed APK but my script failed. What should I change or add?

I add variables KEYSTORE_FILE, KEYSTORE_PASSWORD, KEY_ALIAS, KEY_PASSWORD with values.

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

Error:

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

But it should be successfully

barbsan
  • 3,418
  • 11
  • 21
  • 28

1 Answers1

6

Provided you have correct indentations (as posted they are not), the problem is likely to be caused by multi-line command - it just executes - ./gradlew assembleRelease first, without further arguments

To wrap the long line you can use YAML multi-line strings:

  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

Read more:

--

Another possible cause - if your env var is set as Protected in project settings,
and you are working in a branch which is not Protected.
Then var is not passed to your job

Ivan
  • 9,089
  • 4
  • 61
  • 74
  • 1
    Another possible cause - if your env var is set as Protected in project settings, and you are working in a branch which is not Protected. Then var is not passed to your job. – Ivan Jul 05 '19 at 07:26
  • it's good, but now i have different error. It said that base 64: invalid input. Should i add the extension of my keystore? – Jerico Renzo Vicedo Jul 05 '19 at 07:45
  • @Ivan i got this error: $ echo -n $KEYSTORE_FILE | base64 -di > my.keystore base64: invalid input. can you help me, please. – Masoud Mokhtari Apr 27 '20 at 07:18
  • I found solution. That must be like this: - echo -n %KEYSTORE_FILE% | base64 -di > $(pwd)/my.keystore – Masoud Mokhtari Apr 27 '20 at 08:41
  • @Ivan I got this error now: /bin/bash: line 109: -Pandroid.injected.signing.store.file=/builds/Masoud799/derbiapp/my.keystore: No such file or directory. please help me. – Masoud Mokhtari Apr 27 '20 at 10:45