Hello Team, I want to retrieve credentials from wi...
# community-support
s
Hello Team, I want to retrieve credentials from windows credentials and then I want to apply plugin (customized one, present at artifactory that needs credentials) is it achievable. I tried different ways however no luck. could you please assist how we can do it
v
I have no idea, but I somehow doubt it is possible if I got you right. Here the supported credential types are documented: https://docs.gradle.org/current/userguide/supported_repository_protocols.html So if you somehow get to the actual user and password, or something like a token that you can send in a HTTP header for authentication, it might probably work, but I'm not aware of anything builtin that takes something from Windows credentials store.
but i guess any Provider will be serialised by CC into local cache
v
As username and password are anyway not providers, I'd guess so, that the result is landing in the CC entry, yes, but not sure. Still you could use a value source to make the CC entry out of date if the stored credentials changed, but still the credentials will probably be part of the CC entry.
s
Hi all, I’m trying to retrieve credentials from the Windows Credential Manager and pass them to a custom plugin during the Gradle build. At the moment, the logic for fetching credentials works fine — but it executes after apply plugin, so the plugin doesn’t receive the username/password values in time, causing an unauthorized access error. Here’s what I currently have implemented for context: def mavenUserProp = project.findProperty('mavenUser') def mavenPasswordProp = project.findProperty('artifactoryPwd') if (mavenUserProp && mavenPasswordProp) { logger.lifecycle("Using Bamboo-provided credentials.") ext.mavenUser = mavenUserProp ext.mavenPassword = mavenPasswordProp } else { logger.lifecycle("Bamboo credentials not found, retrieving from Windows Credential Manager.") try { apply from: "$rootDir/windowsCredentialManager.gradle" def cred = getWindowsCredential("jfrogcred") if (cred != null) { ext.mavenUser = cred.username ext.mavenPassword = cred.password } else { throw new GradleException("Credential 'jfrogcred' not found in Windows Credential Manager.") } } catch (Exception e) { throw new GradleException("Failed to retrieve credentials: ${e.message}", e) } } allprojects { apply plugin: "java" apply from: "$rootDir/version.gradle" apply from: "$rootDir/dependencies.gradle" apply plugin: "scmplugin" // fails with unauthorized access } Has anyone found a way to ensure such credential-fetching logic runs before the plugin is applied, or an alternative hook to initialize these values early in the build lifecycle?
v
Like you have it - besides that you use various discouraged bad practices - does run before the
scmplugin
is applied, unless it is applied additionally somewhere before that snippet somehow.
s
any way we can apply a customized plugin - after retrieving credentials
v
I don't get your question
s
I wanted to get user.pass from windows credential manager and then use those to retrieve my custom plugin classpath, so that I can apply that custom plugin. right now getting 401 error - user.pass are null. meaning when apply getting called that time this variable done have actual values retrieved. gradle always first used to execute plugin or buildscript block and then other things..
k
well, you need to wire with Properties. You can create Property, but query later and it will be expanded only on .get() call
v
Yes,
buildscript
blocks and
plugins
blocks are evaluated up-front, otherwise you don't know and have the classpath to evaluate and execute the build script. So if you need the credentials for a plugin repository, you need get the information accordingly, for example in
pluginManagement
block of the settings plugin where you anyway should declare the plugin repositories.