Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readFile with default #2229

Open
gaborbernat opened this issue Mar 16, 2023 · 6 comments
Open

readFile with default #2229

gaborbernat opened this issue Mar 16, 2023 · 6 comments

Comments

@gaborbernat
Copy link

gaborbernat commented Mar 16, 2023

What feature do you want to see added?

Currenlty it's not possible to use readFile substition with a fallback value.

password: "${file:/data/secret/jenkins-password.txt:-fallback}"

Now this logs a warning.

Upstream changes

No response

@jetersen
Copy link
Member

@gaborbernat can't find the docs but your basically using nested substitution wrong that's all. This is a supported feature.

We have some tests that uses nested substitution:

@gaborbernat
Copy link
Author

That's not the same. That means use an env-var to set the file name. It does not set a default value for readFile without an env-var. https://github.com/jenkinsci/configuration-as-code-plugin/blob/master/docs/features/secrets.adoc#passing-secrets-through-variables suggest the default syntax should work for all not just env-vars.

@jetersen
Copy link
Member

I mean what you want is this: ${${file:/data/secret/jenkins-password.txt}:-fallback}

@gaborbernat
Copy link
Author

gaborbernat commented Mar 20, 2023

But that would log a nasty warning

LOGGER.log(Level.WARNING, String.format(
"Configuration import: Error looking up file '%s' with UTF-8 encoding. Will default to empty string",
key), e);
return null;
🤔 can I avoid that? As in this case the file missing is expected and handled.

@jetersen
Copy link
Member

it gives a warning but it should work.

I think the warning here makes sense, please configure the file.

@jetersen
Copy link
Member

What you're asking for will not be supported because we are using an Apache StrSubstitutor implementation.

Unless your willing to write a customized implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants