简体   繁体   中英

Getting docker: invalid reference format in Jenkins docker build agent

If I run the Docker container like this on my local Mac terminal then it works fine. Here I'm passing an argument IAM Role ARN as arn:aws:iam::182402123491:role/jenkins :-

docker run -d -e XDG_CACHE_HOME=/tmp/go/.cache test-image arn:aws:iam::182402123491:role/jenkins

How can I pass the same argument when running this container as Jenkins build agent inside the Jenkinsfile? I tried below but every time I get docker invalid reference format error.

agent {
    docker {
      image 'test/test-image:latest'
      args '-e XDG_CACHE_HOME=/tmp/go/.cache ${AWS_Assume_Role_ARN}'
    }
  }

I'm getting this Jenkins pipeline error:-

java.io.IOException: Failed to run image 'test/test-image:latest'. Error: docker: invalid reference format.
See 'docker run --help'.
    at org.jenkinsci.plugins.docker.workflow.client.DockerClient.run(DockerClient.java:145)
    at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:198)

Jenkins Pipeline declarative DSL and Groovy, like most interpretive languages, requires " to interpolate within strings. ' is used for literal strings.

args "-e XDG_CACHE_HOME=/tmp/go/.cache ${AWS_Assume_Role_ARN}"

Your usage otherwise conforms to Jenkins Pipeline Docker plugin documentation, so this is the only fix necessary here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM