@@ -90,7 +90,14 @@ func run(ctx context.Context, c *cli.Command, backends []types.Backend) error {
9090 hostname , _ = os .Hostname ()
9191 }
9292
93- counter .Polling = c .Int ("max-workflows" )
93+ maxWorkflows := c .Int ("max-workflows" )
94+ singleWorkflow := c .Bool ("single-workflow" )
95+ if singleWorkflow && maxWorkflows > 1 {
96+ log .Warn ().Msgf ("max-workflows forced from %d to 1 due to agent running single workflow mode." , maxWorkflows )
97+ maxWorkflows = 1
98+ }
99+
100+ counter .Polling = maxWorkflows
94101 counter .Running = 0
95102
96103 if c .Bool ("healthcheck" ) {
@@ -201,8 +208,6 @@ func run(ctx context.Context, c *cli.Command, backends []types.Backend) error {
201208 }
202209 log .Debug ().Msgf ("loaded %s backend engine" , backendEngine .Name ())
203210
204- maxWorkflows := c .Int ("max-workflows" )
205-
206211 customLabels := make (map [string ]string )
207212 if err := stringSliceAddToMap (c .StringSlice ("labels" ), customLabels ); err != nil {
208213 return err
@@ -298,6 +303,9 @@ func run(ctx context.Context, c *cli.Command, backends []types.Backend) error {
298303
299304 log .Debug ().Msg ("polling new workflow" )
300305 if err := runner .Run (agentCtx , shutdownCtx ); err != nil {
306+ if singleWorkflow {
307+ ctxCancel (nil )
308+ }
301309 log .Error ().Err (err ).Msg ("runner error, retrying..." )
302310 // Check if context is canceled
303311 if agentCtx .Err () != nil {
@@ -311,13 +319,25 @@ func run(ctx context.Context, c *cli.Command, backends []types.Backend) error {
311319 // Continue to next iteration
312320 }
313321 }
322+
323+ if singleWorkflow {
324+ log .Info ().Msg ("shutdown single workflow runner" )
325+ ctxCancel (nil )
326+ return nil
327+ }
314328 }
315329 })
316330 }
317331
318- log .Info ().Msgf (
319- "starting Woodpecker agent with version '%s' and backend '%s' using platform '%s' running up to %d pipelines in parallel" ,
320- version .String (), backendEngine .Name (), engInfo .Platform , maxWorkflows )
332+ if singleWorkflow {
333+ log .Info ().Msgf (
334+ "starting Woodpecker agent with version '%s' and backend '%s' using platform '%s' running up in single workflow mode" ,
335+ version .String (), backendEngine .Name (), engInfo .Platform )
336+ } else {
337+ log .Info ().Msgf (
338+ "starting Woodpecker agent with version '%s' and backend '%s' using platform '%s' running up to %d pipelines in parallel" ,
339+ version .String (), backendEngine .Name (), engInfo .Platform , maxWorkflows )
340+ }
321341
322342 return serviceWaitingGroup .Wait ()
323343}
0 commit comments