# Facing issue in Jenkinfile while running the Jenkins Docker build agent

**URL:** <https://community.jenkins.io/t/facing-issue-in-jenkinfile-while-running-the-jenkins-docker-build-agent/534>\
**Category:** Ask a question\
**Tags:** question\
**Created:** [October 13, 2021, 5:22pm UTC](https://community.jenkins.io/t/facing-issue-in-jenkinfile-while-running-the-jenkins-docker-build-agent/534 "2021-10-13T17:22:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinod827](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/vinod827/32/395_2.png) [@vinod827](https://community.jenkins.io/u/vinod827)\
**Post date:** [October 13, 2021, 5:22pm UTC](https://community.jenkins.io/t/facing-issue-in-jenkinfile-while-running-the-jenkins-docker-build-agent/534/1 "2021-10-13T17:22:32Z")

</div>

Hi,

I have a customized Docker image that I’m trying to run as a Jenkins docker build agent. Refer to the Jenkins official doc here [Using Docker with Pipeline](https://www.jenkins.io/doc/book/pipeline/docker/)

However, getting this following error:-

```
**java.io.IOException: Failed to run image 'jenkinsagent/test-image:1.1.0'. Error: docker: invalid reference format.**

```

That argument ‘ **abc** ’ is not getting passed properly in the following piece of code of Jenkinsfile:-

```auto
 agent {
        docker {
          image 'jenkinsagent/test-image:1.1.0'
          args '-v ${HOME}/new/test/.aws:/root/.aws:ro -e XDG_CACHE_HOME=/tmp/go/.cache abc'
        }
      }

```

If I run the same container on my local terminal by sending the same argument ‘ **abc** ’ then it works fine:-

```
  `docker run -v $PWD/.aws:/root/.aws:ro -e XDG_CACHE_HOME=/tmp/go/.cache jenkinsagent/test-image:1.1.0 abc`

```

If I do not pass that argument then the container works fine in the Jenkins server as well however my requirement is to pass that argument only. May I know how can I pass any arguments in the following syntax of Jenkins docker build agent:-

```auto
    agent {
        docker {
          image 'jenkinsagent/test-image:1.0.0'
          args '-v ${HOME}/new/test/.aws:/root/.aws:ro -e XDG_CACHE_HOME=/tmp/go/.cache abc'
        }
      }

```

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [October 13, 2021, 5:29pm UTC](https://community.jenkins.io/t/facing-issue-in-jenkinfile-while-running-the-jenkins-docker-build-agent/534/2 "2021-10-13T17:29:33Z")

</div>

> [@vinod827](#):
>
> `abc`

I think its your args abc, the docker image needs to go second last, then the command you want to run. docker.args will be prepended to the image, so it think the image is abc

I Would recommend letting jenkins handle your args for you, by adding `environment { XDG_CACHE_HOME="/tmp/go/.cache" }` instead of of doing it with -e  
if your just wanting to run abc, you should `sh("abc")` inside of a step. Jenkins needs to run the container, then connect inside of it, usually uses cat to do this, then you can run normally.

So something like (untested and written by hand):

```auto
pipeline {
   agent {
     docker {
       image 'jenkinsagent/test-image:1.0.0'
       args '-v "${HOME}/new/test/.aws:/root/.aws:ro"'
    }
  }
environment {
  XDG_CACHE_HOME="/tmp/go/.cache"
  // I would also do HOME="${WORKSPACE} so you don't need the args -v
 }
stages {
  stage('Run abc') {
    steps {
      sh('abc')
     }
  }
}
}

```

or something. [https://github.com/halkeye/infinicatr/blob/376aec6e28000e244f5d02f4155d405486f2d402/Jenkinsfile](https://github.com/halkeye/infinicatr/blob/376aec6e28000e244f5d02f4155d405486f2d402/Jenkinsfile) would be one example I have
