Problem: Scheduled Task doesn't save params
Issue
When creating a scheduled execution of playbook, I want to specify task params - as supported in the 2.16 release.
This is the payload that was sent from the browser:
But when retrieving the details of the scheduled task, it is empty:
And in the task_params_id column of the database table, it's a null value:
Impact
Service (scheduled tasks, alerts)
Installation method
Docker
Database
Postgres
Browser
No response
Semaphore Version
2.16.18
Ansible Version
Logs & errors
No response
Manual installation - system information
No response
Configuration
No response
Additional information
No response
Bump. I'm seeing the same thing on v2.16.1 and 2.16.31. It's also not saving --limit fields when creating the schedule for an ansible playbook. Also on Docker; MySQL.
Same issue here. Just upgrade to the latest version and it broke my schedule jobs. Very disappointing as I now have to hard code them or downgrade the version which I'm weary might cause other issues.
@bverkron I tried downgrading to a version pre-v2.16 and the container wouldn't even start due to a db compatibility issue so I think we're stuck for the timebeing. I"m also hard coding limits in the template itself which is less than ideal.
@Firetend bummer, that's what I was afraid of. Thanks for saving me the effort.
Same issue for me. I tried setting default values for the parameters — at that point, the preset values are displayed in the scheduled task configuration. However, if I try to modify them and save the configuration, reopening it always shows the default values again. When the scheduler runs the task, the default values are overwritten with empty ones.
Sempahore ver: v2.16.31-d14fa6b-1758101449 Database: BoltDB
I had a patch created for my local version (GPT).
However, it only fixes the behavior for SQL databases and not for BoltDB.
Since I don't know Go and just wanted to fix this for myself, I won't be creating a pull request for it.
But anyone who knows Go is welcome to take this on.
diff --git a/db/sql/schedule.go b/db/sql/schedule.go
index 6cc0a0ff..57bc446e 100644
--- a/db/sql/schedule.go
+++ b/db/sql/schedule.go
@@ -5,13 +5,32 @@ import (
"github.com/semaphoreui/semaphore/db"
)
+// hasTaskParamsData returns true if the incoming TaskParams struct contains
+// any meaningful data. We cannot rely on TaskParamsID (it's json:"-" and never
+// sent by clients). This keeps the change minimal and avoids altering API.
+func hasTaskParamsData(p db.TaskParams) bool {
+ if p.Environment != "" { // Environment is empty string by default
+ return true
+ }
+ if p.Arguments != nil || p.GitBranch != nil || p.Version != nil || p.InventoryID != nil {
+ return true
+ }
+ if p.Message != "" { // Message default is empty
+ return true
+ }
+ if p.Params != nil && len(p.Params) > 0 { // Params map has content
+ return true
+ }
+ return false
+}
+
func (d *SqlDb) CreateSchedule(schedule db.Schedule) (newSchedule db.Schedule, err error) {
- if schedule.TaskParamsID != nil {
+ // Insert task params if client sent any task params data.
+ if hasTaskParamsData(schedule.TaskParams) {
params := schedule.TaskParams
params.ProjectID = schedule.ProjectID
- err = d.Sql().Insert(¶ms)
- if err != nil {
+ if err = d.Sql().Insert(¶ms); err != nil {
return
}
schedule.TaskParamsID = ¶ms.ID
@@ -50,29 +69,26 @@ func (d *SqlDb) SetScheduleLastCommitHash(projectID int, scheduleID int, lastCom
}
func (d *SqlDb) UpdateSchedule(schedule db.Schedule) (err error) {
+ // Always load current schedule so we can preserve existing TaskParamsID when
+ // no new task params were provided.
+ var curr db.Schedule
+ if err = d.getObject(schedule.ProjectID, db.ScheduleProps, schedule.ID, &curr); err != nil {
+ return
+ }
- if schedule.TaskParamsID != nil {
- var curr db.Schedule
- err = d.getObject(schedule.ProjectID, db.ScheduleProps, schedule.ID, &curr)
- if err != nil {
- return
- }
-
+ if hasTaskParamsData(schedule.TaskParams) {
params := schedule.TaskParams
params.ProjectID = schedule.ProjectID
-
if curr.TaskParamsID == nil {
- err = d.Sql().Insert(¶ms)
+ if err = d.Sql().Insert(¶ms); err != nil { return }
} else {
params.ID = *curr.TaskParamsID
- _, err = d.Sql().Update(¶ms)
+ if _, err = d.Sql().Update(¶ms); err != nil { return }
}
-
- if err != nil {
- return
- }
-
schedule.TaskParamsID = ¶ms.ID
+ } else {
+ // Keep existing link if client didn't send task params data
+ schedule.TaskParamsID = curr.TaskParamsID
}
_, err = d.exec("update project__schedule set "+
Same issue for me. I tried setting default values for the parameters — at that point, the preset values are displayed in the scheduled task configuration. However, if I try to modify them and save the configuration, reopening it always shows the default values again. When the scheduler runs the task, the default values are overwritten with empty ones.
Same at ... Sempahore version: v2.16.32-d2c2b4a-1760089605 Database: Postgres
I'm also running in to this on version v2.16.34-87a1c53-1760097750.
i forked the repository and applied the fix: https://github.com/m3l0n-sq/semaphore. it's been working well for me for the past week.
not creating a PR since it's generated by claude code, and i'm not familiar with Go.
Appreciate your fork @m4l0n, we've been running on it for the last few weeks as well. Would love to get a fix merged back upstream!
similar problem here... please fix it it possible.
Same problem, had opened a ticket but closed it since I didn't see this one https://github.com/semaphoreui/semaphore/issues/3471