Home > Enterprise >  Jenkins Groovy Error For Credentials in Pipeline
Jenkins Groovy Error For Credentials in Pipeline

Time:09-17

I have a script and part of it is:

              stage('plan') {
                withCredentials([
                    [$class: 'AmazonWebServicesCredentialsBinding', credentialsId: aws_cred_id,
                      accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
                    string(credentialsId: 'xxxxcredx', variable: 'TF_VAR_token') {
                  docker.withRegistry('https://registry-1.docker.io/', 'dockerhub-creds') {

Now when this is run in Jenkins I see the output as:

java.lang.IllegalArgumentException: Expected named arguments but got [{credentialsId=xxxxcredx, variable=TF_VAR_token}, org.jenkinsci.plugins.workflow.cps.CpsClosure2]

how can I fix or modify my script to not get this error bu actually let jenkins pick the credential and the var value.

CodePudding user response:

i believe it should be like this (can't check)

credentials-binding docs: https://www.jenkins.io/doc/pipeline/steps/credentials-binding/

withCredentials([
    aws(credentialsId: aws_cred_id, accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'),
    string(credentialsId: 'xxxxcredx', variable: 'TF_VAR_token'),
]) {
    docker.withRegistry ...
}

  • Related