semaphore icon indicating copy to clipboard operation
semaphore copied to clipboard

No Default Values for Survey Variables in Scheduled Tasks

Open lmrlyv opened this issue 1 year ago • 1 comments

Discussed in https://github.com/semaphoreui/semaphore/discussions/2226

Originally posted by lmrlyv July 23, 2024 I use Survey Variables in the Task Template to set values for the variables defined in the vars_prompt section of the playbook. This works fine when I manually trigger the task and enter the values by hand. However, I haven't found a way to set these variables when the task template is scheduled to run automatically. Is there currently a way to achieve this? If not, wouldn't it be better to allow defining default values when creating a schedule?

lmrlyv avatar Jul 29 '24 07:07 lmrlyv

Hi, any suggestions about what @lmrlyv asked? I have pretty the same problem. Almost all my task templates use any survey variables, for example to indicate the host(s), and I have no way to use them using Schedule option. Thanks!

danisct avatar Aug 20 '24 14:08 danisct

I have the same problem here. I have a task with survey variables that have a default value set. When the task is started via the schedule, it fails.

Image

When I restart the failed task via the web GUI, the variables are already filled in correctly. All I have to do is click ‘Run’ for the task to run smoothly.

Image

lug-gh avatar Jul 31 '25 07:07 lug-gh

Hi, @lug-gh and @danisct

Previously, you couldn't even set default values for the Survey variables. I can see that we can now, but apparently (according to @lug-gh's comment), it's not working when tasks are scheduled. Until a fix is implemented, I have a workaround.

Workaround:

I created two nearly identical projects in Semaphore:

  • "<project-name> (manual)" for tasks triggered manually
  • "<project-name> (auto)" for scheduled tasks

The only difference in the "auto" project is how I handle variables. Instead of relying on survey variables, I pass the necessary default values directly as CLI args to --extra-vars:

--extra-vars '{"key1": "value1", "key2": "value2"}'

See examples below:

Task Template in the "manual" project: Image

Same Task Template in the "auto" project that can be scheduled: Image

Note that --extra-vars accepts key values in a JSON format in this case!

lmrlyv avatar Jul 31 '25 09:07 lmrlyv

@lmrlyv Thank you for providing your workaround. It works for me too, but I would appreciate it if the actual bug could be fixed so that we don't have to work with workarounds.

lug-gh avatar Jul 31 '25 09:07 lug-gh