allow for setting variables for future steps from within a step #2266
Replies: 4 comments 12 replies
-
Did this get introduced in some version? Especially with plugins, I can't find a way to share a value from a previous step, and reuse it in the settings section... |
Beta Was this translation helpful? Give feedback.
-
Has there been any substantive progress in this discussion? |
Beta Was this translation helpful? Give feedback.
-
I am really interested in writing a proposal/implementation for this feature with something more in-line with tools like GitHub Actions. Would just like to get opinions from any of the maintainers if this is something we would like to spend time on before putting it that effort. |
Beta Was this translation helpful? Give feedback.
-
Plugins cannot use arbitrary envsWe could agree (make a "standard") on where to place
Importing from a general step would be like
And for plugins we could add to plugin-template some code, which load envs from standard directory or file ( I think this discussion could be closed as
Or move to something like |
Beta Was this translation helpful? Give feedback.
-
Clear and concise description of the problem
Sometimes a lot of work has to be done to prepare environment variables for their future use, while I can mostly do this within the step (just run some commands, potentially even from a yaml variable), it becomes problematic when using plugins, as they don't (usually) support running commands in their environment before running.
This problem currently affects me the most with the plugin-docker-buildx, where we need to prepare some build-args to be passed into the plugin. Though it would also ease many other things I'm currently doing in pipelines.
Suggested solution
Allow a step to export variables for use in the following steps, this could be done by either providing a way to write them to a file, which is injected as environment in the following steps, or by an explicit mechanism (i.e. calling a specific command, which woodpecker reacts to).
To properly steer / control this, a flag within the step should exist, which either allows "any" exports, or take the variable names, which are exported to the next steps.
a short (likely not syntactically correct) idea... just as a discussion start
I've left out the "normal" options (this should just be an add-on)
While being able to also use the variables directly (within the pipeline yaml and not the executed image) would be nice, I believe this could overcomplicate things.
Alternative
This could also be implemented in a more hands off way, by providing a second mountpoint (additional to the normal working directory), which a step can write into a file, which could then be included in the starting-script of steps (by woodpecker)...
Basic example (as always, just the addition and usecase, may not be valid yaml as I'm just quickly typing this up in the browser...)
The first approach would IMHO be more solid, while this one would likely be easier to implement (except the potential issue with plugins), though it could potentially be "bodged" by just running an additional command in the script_.go / script.go
Additional context
Some other CIs have this feature either by design (explicitly implemented for the purpose) or by happy accident (e.g. Gitlab-CI when not using containers, as steps share the env...).
Being able to prepare variables becomes especially important, when using plugins that are privileged, as the user cannot replace them easily with something that prepares the env as he needs it (esp. so when used in a shared setting like e.g. at Codeberg or in a company/community setting, where devs should not be allowed to declare their own things as privileged).
Validations
Beta Was this translation helpful? Give feedback.
All reactions