When creating my own Docker action, I can pass arguments to it using `with` key in my workflow yml file. For instance
- name: Run tests in the container uses: firstname.lastname@example.org with: wp-db-name: 'wordpresstest' wp-db-user: 'admin' wp-db-pass: 'password' wp-db-host: 'mysql' wp-user: 'admin' wp-pass: 'password'
In my action's entrypoint.sh script I can then reference the `wp-db-name` with $1, `wp-db-user` with $2, etc.
Is it possible to have a key that will have a value that is an array, like:
option: [option1, option2, option3]
If that is possible, how would I reference that in my entrypoint.sh?
Are those inputs passed as env variables inside the script that I could then reference with names instead of numbers, like `$wp-db-name` etc.?
The aim is to reference that key with array value so that I can loop through it in my bash script.
Solved! Solved! Go to Solution.
Hi @dingo-d ,
The input variable type only supports string , number and boolean. So an input key with array value is not supported. You could consider to convert the string into array in entrypoint.sh .
>>Are those inputs passed as env variables inside the script that I could then reference with names instead of numbers, like `$wp-db-name` etc.?
There are env variables for inputs when using the docker container action. But the env name has an INPUT_ prefix and all the letters are in uppercase. Please note that '-' is an invalid charture in shell variable name, you could use ‘_’ instead. I change all the input variables to use '_' . Such as 'wp_db_name' .
You could use $INPUT_WP_DB_USER in your entrypoint.sh.
There is the action setting in workflow yml:
- uses: ./ with: who_to_greet: '[1,2,3]' wp_db_name: 'wordpresstest' wp_db_user: 'admin'
And entrypoint.sh example:
#!/bin/sh -l echo "Hello $1" time=$(date) echo $INPUT_WHO_TO_GREET echo $INPUT_WP_DB_USER echo ::set-output name=time::$time newstr=$(echo $INPUT_WHO_TO_GREET | sed 's/\[//g' ) # remove [ newstr2=$(echo $newstr | sed 's/\]//g' ) # remove ] echo $newstr2 IFS=, # split on , set -o noglob # disable glob set -- $newstr2 # split+glob with glob disabled. echo "$# elements:" printf '"%s"\n' $@
Thank you for the explanation! I'll see about using string and converting it to array in the entrypoint, that's a useful tip, as well as with the inputs :)