Apply usernamePassword(credentialsId: env.CREDENTIALS, .. ) to provide selected credential to the script as custom variables, example:
steps {
withCredentials([ usernamePassword(
credentialsId: env.CREDENTIALS,
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD') ]) {
script {
sh( script: "./my_shell_script.sh" ) // echo "$USERNAME, $PASSWORD"
}
}
}
.. see my detailed answer to a similar question: https://stackoverflow.com/a/79197253/1745341