Hello,
I’d like to send a build API request with a specific workflow, that includes the steps inputs.
For example, I have a workflow with steps, one of them is “Step A” which has the following parameters in its step.yaml:
inputs:
- build_to_test: “None”
opts:
value_options:
- “None”
- “Bitbar”
- “Browserstack”
- “Saucelabs”
- “Lambdatest”
is_required: true
In my API implementaion:
self.env_vars = [
{“mapped_to”: “build_to_test”, “value”: ‘Saucelabs’, “is_expand”: True},
{“mapped_to”: “TEAM_ID”, “value”: self.team_id, “is_expand”: True},
]
client_payload = {
“build_params”: {
“branch”: “master”,
“workflow_id”: self.workflow_id,
“environments”: self.env_vars
},
“hook_info”: {
“type”: “bitrise”
}
}
response = requests.post(url, json=client_payload, headers=self.headers)
The build initiates with the correct workflow but the actual build_to_test value is still None. While $TEAM_ID is properly set.
What am I doing wrong?
Thanks.
Hi @elish266
Based on the example it seems that you have a specific value set for the build_to_test
step input.
If you want to use a value provided via the API, you have to set the step’s input value to an environment variable and then specify that env var via the API.
So, instead of:
- build_to_test: “None”
opts:
...
You could set the value of the step input to let’s say $BUILD_TO_TEST
- build_to_test: “$BUILD_TO_TEST”
opts:
is_expand: true
Note: I added is_expand: true
to opts
to ensure the specified value for the input will be handled as an env var, and the value of the env var will be used as the input’s value.
Note that if you change this then you’ll have to specify the BUILD_TO_TEST
env var; if it’s empty no value will be set for the input.
If you want to have a single workflow which can do both - using a default value while also allowing override via the API - you can add a “Set Environment Variable” step before this step, setting a default value for the env var if the env var isn’t set yet:
- set-env-var@0:
title: Set default value for BUILD_TO_TEST
inputs:
- destination_keys: BUILD_TO_TEST
- value: 'None'
run_if: '{{enveq "BUILD_TO_TEST" "test value"}}'
This step will only run if BUILD_TO_TEST
isn’t specified (run_if: '{{enveq "BUILD_TO_TEST" "test value"}}'
), and in that case it’ll set the BUILD_TO_TEST
env var to the value you specify (here in the example it sets the value to 'None'
as that was the value in your example).
Add this “set default value” step before the other step.
If you’d have any question let us know.
Happy building!