Open june128 opened 3 months ago
This is the expected behavior and not a bug.
Our current workflow of substitution does not allow to do something like this, it can only work with vars that are equal for the whole workflow.
skip_clone: true
steps:
echo-envs:
image: alpine
environment:
MY_COOL_TEST_VAR: test
commands:
- echo "Workspace is $$CI_WORKSPACE"
- echo "My cool variable is $$MY_COOL_TEST_VAR"
+ echo "Workspace is $CI_WORKSPACE"
Workspace is /woodpecker/src/gitea.example.com/wp/test
+ echo "My cool variable is $MY_COOL_TEST_VAR"
My cool variable is test
or use scripts.
@qwerty287 Ahh fair enough, that's unfortunate. I guess having this clarified in the docs would be a good idea and this issue can be considered a feature request then.
@zc-devs But I want to have the value of MY_COOL_TEST_VAR
, not the variable name. How does escaping it help me then?
What is this then?
@zc-devs Yeah, it works when using regular environment variables, but it doesn't work with string substitution (${MY_COOL_TEST_VAR}
).
For commands
I can of course just use regular environment variables, however I only used the commands
key as a simple example. A use case I have in particular is using the value of a custom environment variable in entrypoint
, where only string substitution is available. There one then just can't use custom environment variables.
A friend pointed out a workaround for this problem.
One can abuse the matrix
key for setting values, which then can be accessed using string substitution. Not perfect, but it works.
It might be nice to have a lightweight matrix
key named environment
to facilitate global environment variables. However this is then another feature request.
It should work when you try to escape that one as well: $${MY_COOL_TEST_VAR}
@anbraten That seems to work only in shells, but not if you want to use the variable in an entrypoint without a shell directly.
Could be solved much more easily by doing something like https://github.com/woodpecker-ci/woodpecker/discussions/2473#discussioncomment-10129727 I think
Component
server, agent
Describe the bug
Setting custom environment variables using the
environment
key can't be used via string substitution.Steps to reproduce
Expected behavior
The output being:
What's actually being output:
System Info
Additional context
Woodpecker running on NixOS. Config available here.
Validations
next
version already [https://woodpecker-ci.org/faq#which-version-of-woodpecker-should-i-use]