1

I use Cordova CLI to create Android APKs on my Ubuntu 16.04 VPS server. Once the APK has been built I copy it to Dropbox on local machine and then install the APK on my Android test devices. I want to use the Dropbox API to upload the APK directly so I avoid the unnecessary 3 way transfer:

Server -> Local Machine -> Dropbox -> Android test device.

The sequence of operations would go like this

  • Shell scripts (already written) on the server cleanup the Android source and rebuild the APK
  • This is done with Phonegap/Cordova verbose output on which ensures that a successful build emits the following text at the end

BUILD SUCCESSFUL

 Total time: 5.495 secs
 Built the following apk(s): 
 /path/to/app/source/platforms/android/build/outputs/apk/android-debug.apk


No scripts found for hook "after_compile".


No scripts found for hook "after_build".


[36m[phonegap][39m completed 'cordova build android -d --no-telemetry'

The final step - uploading the android apk to my Dropbox should only be done if BUILD SUCCESSFUL is found in the Cordova/Phonegap debug output. I have got everything in place but I am not sure how I should check for BUILD SUCCESSFUL

Here is the pseudocode in the shell script

!# /bin/bash
pgclean;
# pgclean is another shell script that cleans up the Phonegap project in the 
# current folder
pgbuild;
# this rebuilds the APK and saves the detailed debug output to
# /path/to/my/project/debug.txt
# it is debug.txt which would contain BUILD SUCCESSFUL etc

Here is where my knowledge of bash scripts hits the buffers. What I would like to do next:

  • Test debug.txt, above, to ensure that the build is successful
  • If so call my final shell script

    moveapktodropbox $1

where $1 is the parameter I pass to the current shell script to provide the name under which the APK should be stored in Dropbox.

2 Answers 2

3

With POSIX every program should exit with a status code: 0 means success, 1 warning, 2 and more error.

You could test if the process build exit with status code 0.

buildprocess
if [ $? -eq 0 ] ; then otherscript ; fi

$? means last status code

or more concise:

buildprocess && otherscript
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this - not what I did in the end but it adds to my knowledge anyway.
0

I eventually ended up doing this

x=$(grep -c "BUILD SUCCESSFUL" /path/to/my/app/debug.txt);
if [ $x -eq 1 ]; then
 moveit $1;
 echo "Good Build";
 exit;
fi;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.