With your example, you have specified correctly for AmazonWebServicesCredentialsBinding and missed the secret file details. It will be like the below example:
pipeline {
agent any;
stages {
stage('debug') {
steps {
withCredentials([
file(credentialsId: 'secret-file', variable: 'FILE'),
[
$class: 'AmazonWebServicesCredentialsBinding',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
credentialsId: 'awstoEKS',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
]
]) {
sh """
cat $FILE
curl -u $AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY https:/do.something.aws.com > output
"""
}
}
}
}
}
If I correct your example it will be:
....
steps {
withCredentials([
file(credentialsId: 'kubeconfig', variable: 'kubeconfig'),
[
$class: 'AmazonWebServicesCredentialsBinding',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
credentialsId: 'awstoEKS', // ID of credentials in Jenkins
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
]
]) {
sh """
echo 'do something with' $kubeconfig $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY
"""
}
}
you can find more example from jenkins documentation
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…