Run Workflow step from script in repository

How is it possible to run a Bitrise Workflow step from a script in my repository?

I have an Android project that has several flavors each containing a different key alias and password.

This is what I need to do:

  1. Gradle Runner step: Assemble all app variants of my project with the eventual output as $BITRISE_APK_PATH_LIST.
  2. Execute a script in my repo using the Script step to iterate over each app, initially passing in the $BITRISE_APK_PATH_LIST.
  3. For each iteration, execute the Android Sign step in Bitrise from the script in my repo to sign each app.
  4. Execute the Deploy to Bitrise step to access my signed APKs.

Note: I understand I could also deploy to the Google Play Store for each different app I have published during the iteration of my script in my repo.

I haven’t played around with bash scripting that much before (learning this now!), although I need bit of clarification as to how to execute the Bitrise steps on each iteration from my script.

Any help would be greatly appreciated! :wink:

Hi @richardansell!

Thanks for raising this question! :slight_smile: Can you provide us a bit more detail and/or insight on the script itself or what is the purpose of it?

If you simply provide $BITRISE_APK_PATH_LIST to the Android Sign step it will automatically sign each app, so it isn’t entirely clear what does the script do or why it’s needed, but maybe I’m missing something so let me know!

Hi Bence,

Thanks for getting back to me.

From my understanding, although providing the $BITRISE_APK_PATH_LIST to the Android Sign step will automatically sign each app, this is only if the key alias and password are the same. Yet, in my case, they are different for each version of my app. Therefore, the above steps are what I would need to do to accomplish this task unless I’m wrong?

Hey again, I see!

You’re completely right, but as I understood this:

For each iteration, execute the Android Sign step in Bitrise from the script in my repo to sign each app.

You want to run the Android Sign step as many times as the number of apps you’re dealing with, which would mean you can assign different keystore passwords, URLs, and aliases to each instance of the step - which still leaves me a bit unsure what you’d like to make happen in that script :slight_smile:

I guess my main question is how would you like to have the virtual machines gain access to all of these keystore files? Can you zip them and upload them to the Generic File Storage, and then download and unzip those on the VMs?

Hi Bence,

Sorry for the delay!

After looking at this further, I assume I can actually run the following steps locally to achieve what I want:

  1. Gradle Runner: Assemble all app variants of my project with the eventual output as $BITRISE_APK_PATH_LIST.
  2. Script: Execute a custom script in the workflow, not from the repo, and iterate over each app flavor using the $BITRISE_APK_PATH_LIST. For each iteration, use a secret variable to obtain the key alias and password for that app and execute a separate Android Sign step within that iteration, each time using the same keystore but a different key alias and password.
  3. Deploy to Bitrise: Execute step to access my signed APKs.

This actually seems to be the most obvious process to sign each app as I have a single keystore file but different key aliases and passwords for each app, meaning that I’m going to have to sign each app flavor I’ve created.

Is this solution above possible and the best way to achieve what I want? I would need to create the secret variables for the key aliases/passwords separately beforehand, but I can associate each one with the correct app from the $BITRISE_APK_PATH_LIST using the app name I assume?

Look forward to your reply.

Richard

Hi @richardansell!

That is absolutely possible and definitely one of, if not the best way to go about this :slight_smile: Just make sure you add a variable for each APK first, since there is only one for the latest and the list of course, containing all of them. Maybe our envman tool is the most convenient way to handle this, you can find out a bit about that here in case you haven’t yet: GitHub - bitrise-io/envman: Environment variable manager

Hi Bence,

I think I will go down this route as it seems the most easily achievable, and I will look at using envman as the data is only small to contain the key alias and password for each app.

Just to clarify, how would I be able to run a separate Android Sign step for each iteration from the script? I understand if this was executed on my repo, I’d have to execute an API call to do this, yet how would this be possible when it isn’t technically part of the GUI Workflow as it’s contained in the Script step?

Finally, do I need to pass in the signed apps following the Android Sign step to the Deploy to Bitrise.io - Apps, Logs, Artifacts step somehow, i.e. do I also need to run the Deploy to Bitrise.io - Apps, Logs, Artifacts step directly from the Script step during each iteration or does this step handle the logic automatically?

Appreciate your support with this - the documentation could do with instructions on how to achieve this.

Richard

Hi @richardansell, the Deploy to Bitrise.io step will automatically upload any files found in the $BITRISE_DEPLOY_DIR, so if you move the files you’d like to upload into that directory, they should be be uploaded if you include the step at the end of your workflow. :smile:

Thanks for the reply and that does seem to solve the issue from my last paragraph. However, how can I simply execute the Android Sign step for each iteration from my custom Script step, as per above?

If I’m looping through each app from the $BITRISE_APK_PATH_LIST in my custom Script step, I will need to execute the Android Sign step for each different app, i.e. different key alias/password. I assume I can call the Android Sign step within the script as it’s all within Bitrise and not my repo, negating the need to run a Curl command.

Hi @richardansell!

Most of our steps uses command calls (which can happen from a script step also). If you need to run a step, then you would need to clone the step repo under the GOPATH, set the required input envs and then call ./step.sh or go run *.go

This way everything becomes possible with Bitrise :sunglasses:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.