0

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.

devgirl
  • 671
  • 3
  • 16
  • 39
  • I found this question https://stackoverflow.com/questions/36931114/error-expected-named-arguments-in-parallel-in-jenkins-groovy-script/36931213 which maybe similar .. but I still do not know how to fix my script – devgirl Sep 13 '21 at 20:14
  • i don't see in examples the ability to use `string(...)` inside closure `{ ... }`. i think you have to move it into `withCredentials([ ... ])`. https://www.jenkins.io/doc/pipeline/steps/credentials-binding/ – daggett Sep 14 '21 at 14:01

1 Answers1

1

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 ...
}

daggett
  • 26,404
  • 3
  • 40
  • 56