semaphore icon indicating copy to clipboard operation
semaphore copied to clipboard

Feature: Survey variables in the environment

Open geckoadi opened this issue 1 year ago • 5 comments

Related to

Other

Impact

nice to have for enterprise usage

Missing Feature

I really like the feature of 'Survey Variables' in bash tasks! However, they are currently passed as the argument NAME=value. This is very impractical. Wouldn't it be better to pass them into the environment of the new shell? Then they can be accessed natively and you don't have to separate them from other arguments.

Implementation

I'm not in the code, but I can guess that the implementation can't be very difficult, the variables just need to be exported to the environment of the new shell. Everything is made for it. :-) Thanks!

Design

No response

geckoadi avatar Oct 17 '24 05:10 geckoadi

Hi @geckoadi

yes, I agree. It should be env vars.

fiftin avatar Oct 21 '24 16:10 fiftin

Please give consideration if changing this to existing users using the functionality who have built around the way it works currently. (Remember #2229 for the last time this was broken and the fix in #2288)

ShaneMcC avatar Nov 04 '24 05:11 ShaneMcC

I think you can just do both, put the variables in the environment AND in the argument list. However, I don't think the variables in the arguments make sense, because that's where the arguments (and possibly options) belong. Supporting both can get confusing. The sooner you decide on an option, the better. Personally, I find poll variables in the environment more elegant. They are much easier to use than via the arguments, where you have to separate them from other arguments in a ‘complex’ way. ;-)

for ARG in "$@"; do [[ "$ARG" == "=" ]] && eval "$ARG"; done

If you use the variables from the environment, you only need to skip the ‘eval’ line, right?

geckoadi avatar Nov 05 '24 08:11 geckoadi

This seems like a no-brainer to me, especially when provisioning VMs or LXCs through Terraform/OpenTofu.

MaxPtg avatar Jan 30 '25 16:01 MaxPtg

Mainly adding to this to track any updates. I also created a discussion here:

https://github.com/semaphoreui/semaphore/discussions/2961

... in case anyone has any input or want to get some additional perspectives.

In any case, some better documentation for the Bash feature would be nice, as I think right now it's a bit hard to understand how it's supposed to work. The NAME=value argument output is not what I anticipated and it definitely didn't work with the script I had written. Normally I would've written an Ansible playbook to do what I needed, but there was no Ansible module available, so I used a Bash script instead. However, I can't really use that Bash script with Semaphore as I intended now.

mlanner avatar Apr 28 '25 18:04 mlanner