AWS SDK can not read environment variables AWS SDK can not read environment variables jenkins jenkins

AWS SDK can not read environment variables


You should be able to change the credentials file location using the AWS_CREDENTIAL_PROFILES_FILE environment variable


I am assuming you are configuring your Jenkins Job with different build steps between set credential and consume credential.
Jenkins does not share environment variable between build steps.

If you are using old-style of Jenkins job you will need to use some Plugin like envinject, or use a file to share the variables between steps. Like below (just as example).

Step 1

echo "export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" > credentialecho "export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" >> credentialecho "export AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}" >> credential

Step 2

source credential && ./your_command_here

But if you are suing Jenkins Pipeline, you can use env. Like below (just as example).

  pipeline {        parameters {            string(name: 'AWS_ACCESS_KEY_ID', defaultValue: '')        }        stage("set credential") {             steps {               tmp_AWS_ACCESS_KEY_ID =  sh (script: 'your shell script here', returnStdout: true).trim()               env.AWS_ACCESS_KEY_ID = tmp_AWS_ACCESS_KEY_ID              }        }        stage("consume credential") {            steps {              echo "${env.AWS_ACCESS_KEY_ID}"            }        }  }