| When running via declarative pipeline, any variables bound via Credentials Binding plugin are empty and cannot be used on the running pod. The environment variable should be set via the `withCredentials` but never does.
stage('Run Playbook') {
steps {
script {
withCredentials([string(credentialsId: "ocp-${params.Environment}-ansible-sa-token", variable: 'K8S_AUTH_API_KEY')]) {
sh "printenv" // K8S_AUTH_API_KEY env var is completely missing
...
// Any steps relying on K8S_AUTH_API_KEY (the k8s Ansible module in this case) fails since that variable is never set.
I've seen a number of PRs opened to address other environment variables set by Jenkins itself (ie. COMMIT_ID and other SCM related vars). However, no combination of withCredentials seems to work when running inside a pod. |