I have the following step in my declarative jenkins pipeline: I create script which comes from my resources/
folder using libraryResource. This script contains credentials for my autobuild
user and for some admintest
user.
stage('Build1') { steps { node{ def script = libraryResource 'tests/test.sh' writeFile file: 'script.sh', text: script sh 'chmod +x script.sh' withCredentials([usernamePassword(credentialsId: xxx, usernameVariable: 'AUTOBUILD_USER', passwordVariable: 'AUTOBUILD_PASSWD')]){ sh './script.sh " } } }
This works fine. I can use my autobuild
user. Now I'm searching for the best way how I can include also the crendentials of my admintest
user. Do I have to 'nest' it with a second withCredentials
part or can I add again a usernamePassword
'array'?
Head to the Build Environment section of your job definition. Check Use secret text(s) or file(s). This will actually inject the secret into your build environment. The "Credentials Parameter" created earlier can be used here to let you select different credentials parameters.
To configure AWS credentials in Jenkins: On the Jenkins dashboard, go to Manage Jenkins > Manage Plugins in the Available tab. Search for the Pipeline: AWS Steps plugin and choose Install without restart. Navigate to Manage Jenkins > Manage Credentials > Jenkins (global) > Global Credentials > Add Credentials.
Sure, you can use one withCredentials
block to assign multiple credentials to different variables.
withCredentials([ usernamePassword(credentialsId: credsId1, usernameVariable: 'USER1', passwordVariable: 'PASS1'), usernamePassword(credentialsId: credsId2, usernameVariable: 'USER2', passwordVariable: 'PASS2') ]){ //... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With