How to use pipeline credential between pipeline folders?

Jenkins setup: 2.387.3.5

How do we pass a pipeline credential in a pipeline folder to its parent pipeline projects at its parent level ?

Thank you

As far as I know, credentials are typically stored and accessed through the Jenkins Credentials Plugin.

Credentials can be defined at a global level or a specific scope level (like a folder).
To use a credential defined in a pipeline folder in its parent pipeline projects, Ithink you could use the withCredentials step provided by the Credentials Binding Plugin.
This step should allow you to bind your credentials to variables that can be used in your pipeline.

withCredentials([usernamePassword(credentialsId: 'my-credentials-id', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
    // Your pipeline steps here
    // You can use the variables USERNAME and PASSWORD here
}

In this example, my-credentials-id is the ID of the credentials you want to use.
The usernamePassword method is used to bind the username and password of these credentials to the USERNAME and PASSWORD variables, respectively.

You could then use these variables in your pipeline.

Credentials are designed to be accessed only by jobs/pipelines that are in the same folder or in a child folder.
A job/pipeline in a parent folder cannot access credentials defined in a child folder.
This is by design for security reasons.

If you need to use the same credentials in multiple folders, I think you should then define them at a higher level (like the global level) that is accessible to all these folders. :thinking:

thx for responding, poddingue
We have to move credentials to parent level.

1 Like