This message was deleted.
# community-support
s
This message was deleted.
a
is the
SENTRY_AUTH_TOKEN
environment variable being used in a
build.gradle(.kts)
somewhere?
d
No, it is used by some Gradle plugin i use and I've no control of
The "inject environment variable through file" seems quite a common use case for a build system, I'm surprised this wasn't well documented
Btw the plugin add a task to my build, that task go look for the environment variable
a
does the Gradle Plugin expose a property where you can manually set the Sentry auth token value, or does it always fetch it from the environment variable?
d
It look for a properties file inside the my module. But I already need that to set other properties that are committed.
Are you saying there is no way of loading environment variables in Gradle via file?
a
if it’s possible to set it as a property, e.g.
Copy code
// build.gradle.kts

sentryExtension {
  authToken.set("...")
}
then I would use a project Property
Copy code
// build.gradle.kts

sentryExtension {
  authToken.set(providers.gradleProperty("authToken"))
}
because then on the CI machine I can set the environment variable
ORG_GRADLE_PROJECT_authToken=123
, but on my local machine I can set
authToken=123
in
$GRADLE_USER_HOME/gradle.properties
- and they’ll both be picked up
d
No it's not. The task internally execute a command line tool and that command line tool will look for the environment variable
a
if you have to use an environment variable then you could try to create a init script that would set the environment variable, but I don’t think that’s easy in Java https://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java
The task internally execute a command line tool and that command line tool will look for the environment variable
ah well, it is possible to set the environment variables for launched processes
Copy code
val myExecTask by tasks.registering(Exec::class) {
  environment("SENTRY_AUTH_TOKEN", providers.gradleProperty("authToken").get())
}
d
Thanks I've entered a work call but I'll look into it
👍 1
Where can I make feature requests to Gradle?
v
Environment variables are to be supplied by the environment, like the CI server. That's why a running Java process cannot modify the environment variables, unless it forks a new process. Actually Gradle forks a new process from the CLI, the daemon where it then probably could set environment variables.
But you can only configure the JVM arguments that are used for that, because environment variables are, well, meant to be supplied by the environment.
A better place for a feature request would be the tool that requires it as environment variable, or the plugin that calls that tool, so that either of those supports a different way to supply that value.
a
it looks like Sentry CLI supports both an environment variable and a config file? https://github.com/getsentry/sentry-docs/blob/master/src/docs/product/cli/configuration.mdx#to-authenticate-manually
v
You could change the
gradlew
scripts to set your environment variable there actually. But again, don't. 🙂
d
The config file I already use for stuff that has to be committed.
I think this should be supported by Gradle or at least Gradle wrapper, it's such a common need
v
As I described, it is an absolutely uncommon need.
Environment variables are to be supplied by the environment
But feel free to open a feature request, that's just my personal opinion
d
For instance, the gradlew could automatically look for a .env file and load it or, even better, multiple .env files (there are other tools that do that and already have a best practice for it)
v
As I said, feel free to open a feature request and see what the Gradle guys say. But in Gradle you already have file-based environment-specific key-value pairs, so, ... 🙂
d
r
hi @Daniele Segato, Roman from Sentry here 👋 we already have a feature request for that specific case, so I guess I'll just throw a quick PR for that soon, seeing people have a demand for that. https://github.com/getsentry/sentry-android-gradle-plugin/issues/440
❤️ 1
but we won't advertise it much I guess, because there's a risk of leaking tokens if someone sets them directly in the extension lol
d
Thanks @Roman Zavarnitsyn I subscribed to the issue and I'll switch to that when you release it. I still think from the Gradle standpoint it makes sense to support setting env variables via file. What do you mean about the leaking?
r
if you set
sentry.authToken="<my_real_token>"
to your
build.gradle
and then push it to github for example
d
Oh yeah, well that can happen with the
sentry.properties
files as well :-)
r
true!