How to run workflow from script step?

Hi there
How to run workflow from script step?

Hi @AVKarelin!

Can you clarify what is your intention? :slight_smile:

Once you click Start/Schedule build you can select the “Advanced” tab, and if you scroll to the bottom of it you’ll find a curl command to start your build based on your build config settings :slight_smile:

Thanks! It works. But I have App Environment Variables. I script step i set them up in loop reading from a file

envman add --key APP_BRAND --value $BRAND
envman add --key APP_BUNDLE_ID --value $APPBID

Then I run a workflow by curl and I have a script step in this workflow

echo "My App Bundle ID: $APP_BUNDLE_ID"
echo "My App Brand: $APP_BRAND"

But they empty

+ echo 'My App Bundle ID: '
My App Bundle ID: 
+ echo 'My App Brand: '
My App Brand: 

Can you send us an example build URL of this occurring?

https://app.bitrise.io/build/ 1d53377c7c1f5f35

Where exactly is this script located where you specify the variables in the first place?

In start workflow I have script step.

#!/usr/bin/env bash
# fail if any commands fails
set -e
# debug log
set -x
curl -X POST https://react-v2.[***].app/react-api/options/brand?view=all | python3 -c "import sys, json; print(*json.load(sys.stdin)['brand'].keys(), sep='\n')" > ./brands.txt
FILE="./brands.txt"
while read BRAND; do
    envman add --key APP_BRAND --value $BRAND
    APPBID=$(curl -X POST -F "brand=$BRAND" https://react-v2.[***].app/react-api/options/brand | python3 -c "import sys, json; print(json.load(sys.stdin)['brand']['mobile']['ios']['package'])")
    envman add --key APP_BUNDLE_ID --value $APPBID
    curl https://app.bitrise.io/app/[***]/build/start.json --data '{"hook_info":{"type":"bitrise","build_trigger_token":"[***]"},"build_params":{"branch":"dev","workflow_id":"build_ios"},"triggered_by":"curl"}'
done < $FILE

[***] - This is my replacement.
APP_BRAND and APP_BUNDLE_ID - App Environment Variables that can be replace in inputs.
In the called workflow I have script step

#!/usr/bin/env bash
# fail if any commands fails
set -e
# debug log
set -x
echo "My App Bundle ID: $APP_BUNDLE_ID"
echo "My App BRAND: $APP_BRAND"

So these are separate workflows, correct? The one you sent us is named “build” and it only contains this last script step and the “start” workflow didn’t run on this virtual machine before it, which is the reason it couldn’t find it.

When you start a build a virtual machine is created and then destroyed once it’s over, so you will only have access to variables which you declare is seperate workflows

How can I realize my workflows in my case?

Can you perhaps provide a bit more context to this question? What would you like to accomplish? :slight_smile:

There is a pack of ios applications with similar functionality. The customer decided to provide the app settings through the json file. I need to parse it and build according to those settings of apps. He can add more apps and settings in the json file. So it look like a workflow for each app will be the same but with different app_build_id and so on.

Oh I see!

So we’d recommend using the Advanced tab to set these env_vars:

So you receive this command that includes where these variables are mapped to, afterwards you can replace the value with the previously set variables and start builds using this command

Thanks! I tried that now.
So, I have in my first script step

FILE="./brands.txt"
while read BRAND; do
    echo $BRAND
    curl https://app.bitrise.io/app/ea60c7195950cdfb/build/start.json --data '{"hook_info":{"type":"bitrise","build_trigger_token":"ZPcGZyMGvIseGYfIOFjc_g"},"build_params":{"branch":"dev","workflow_id":"build_ios","environments":[{"mapped_to":"APP_BRAND","value":"$BRAND","is_expand":true}]},"triggered_by":"curl"}'
done < $FILE

But in log for my second script step I see APP_BRAND is empty. It look like the variable $BRAND do not work as a value for the env variable $APP_BRAND.

It seems that you have to set is_expand to false. See https://devcenter.bitrise.io/api/build-trigger/#specifying-environment-variables

1 Like

I set is_expand to false. It did not work.

Can you include a build URL about that?

curl https://app.bitrise.io/app/ea60c7195950cdfb/build/start.json --data '{"hook_info":{"type":"bitrise","build_trigger_token":"ZPcGZyMGvIseGYfIOFjc_g"},"build_params":{"branch":"dev","workflow_id":"build_ios","environments":[{"mapped_to":"APP_BRAND","value":"$BRAND","is_expand":false}]},"triggered_by":"curl"}'

This is a cURL command, what I mean is that we’d like to take a look at the build so I mean to ask for that URL :slight_smile: as you’ve done previous with this: Bitrise - Mobile Continuous Integration and Delivery - iOS & Android Build Automation

https://app.bitrise.io/app/ ea60c7195950cdfb

Hy, is this a url the build? :upside_down_face: