semaphore icon indicating copy to clipboard operation
semaphore copied to clipboard

Problem: Scheduled Task doesn't save params

Open m4l0n opened this issue 3 months ago • 11 comments

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:

Image

But when retrieving the details of the scheduled task, it is empty:

Image

And in the task_params_id column of the database table, it's a null value: Image

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

m4l0n avatar Sep 17 '25 03:09 m4l0n

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.

Image

Firetend avatar Sep 25 '25 18:09 Firetend

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 avatar Oct 02 '25 14:10 bverkron

@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 avatar Oct 02 '25 17:10 Firetend

@Firetend bummer, that's what I was afraid of. Thanks for saving me the effort.

bverkron avatar Oct 02 '25 21:10 bverkron

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

abettarini avatar Oct 03 '25 07:10 abettarini

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(&params)
-		if err != nil {
+		if err = d.Sql().Insert(&params); err != nil {
 			return
 		}
 		schedule.TaskParamsID = &params.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(&params)
+			if err = d.Sql().Insert(&params); err != nil { return }
 		} else {
 			params.ID = *curr.TaskParamsID
-			_, err = d.Sql().Update(&params)
+			if _, err = d.Sql().Update(&params); err != nil { return }
 		}
-
-		if err != nil {
-			return
-		}
-
 		schedule.TaskParamsID = &params.ID
+	} else {
+		// Keep existing link if client didn't send task params data
+		schedule.TaskParamsID = curr.TaskParamsID
 	}
 
 	_, err = d.exec("update project__schedule set "+

1xMax42 avatar Oct 04 '25 20:10 1xMax42

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

rslllstefan avatar Oct 16 '25 08:10 rslllstefan

I'm also running in to this on version v2.16.34-87a1c53-1760097750.

stith avatar Oct 16 '25 20:10 stith

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.

m4l0n avatar Oct 24 '25 02:10 m4l0n

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!

stith avatar Oct 30 '25 18:10 stith

similar problem here... please fix it it possible.

vampywiz17 avatar Nov 03 '25 11:11 vampywiz17

Same problem, had opened a ticket but closed it since I didn't see this one https://github.com/semaphoreui/semaphore/issues/3471

invaderb avatar Dec 17 '25 16:12 invaderb