Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-63438

Pipeline docker.build - docker build-arg cause pipeline to fail

      Both of these attempts results in the error 
       "docker build" requires exactly 1 argument.

      I believe this to be a bug since the docker.build works fine without any arguments.

      stage('Build image') {
        steps{
          sh """docker build -t my-image:dev --build-arg VAULT_TOKEN=${VAULT_TOKEN} ."""
        }
      } 

       

      stage('Build image') { 
        steps{ 
          docker.build "my-image:dev", "--build-arg VAULT_TOKEN=${VAULT_TOKEN} ."
        } 
      }  

      When looking at the pipeline output I can see the trailing "." is being removed from the docker.build step

      + docker build -t my-image:dev --build-arg VAULT_TOKEN=<token>
      "docker build" requires exactly 1 argument.
      See 'docker build --help'.
      
      Usage:  docker build [OPTIONS] PATH | URL | - 

          [JENKINS-63438] Pipeline docker.build - docker build-arg cause pipeline to fail

          Gene Gaddy created issue -
          Gene Gaddy made changes -
          Description Original: Both of these attempts results in the error 
           "docker build" requires exactly 1 argument.

          I believe this to be a bug since the docker.build works fine without any arguments.
          {code:java}
          stage('Build image') {
            steps{
              sh """docker build -t my-image:dev --build-arg VAULT_TOKEN=${VAULT_TOKEN} ."""
            }
          } {code}
           
          {code:java}
          stage('Build image') {
            steps{
              docker.build "my-image:dev", "--build-arg VAULT_TOKEN=${VAULT_TOKEN} ."
            }
          } {code}

          When looking at the pipeline output I can see the trailing "." is being removed from the docker.build step


          {code:java}
          + docker build -t master-of-the-universe:dev --build-arg VAULT_TOKEN=<token>
          "docker build" requires exactly 1 argument.
          See 'docker build --help'.

          Usage: docker build [OPTIONS] PATH | URL | - {code}
          New: Both of these attempts results in the error 
            "docker build" requires exactly 1 argument.

          I believe this to be a bug since the docker.build works fine without any arguments.
          {code:java}
          stage('Build image') {
            steps{
              sh """docker build -t my-image:dev --build-arg VAULT_TOKEN=${VAULT_TOKEN} ."""
            }
          } {code}
           
          {code:java}
          stage('Build image') {
            steps{
              docker.build "my-image:dev", "--build-arg VAULT_TOKEN=${VAULT_TOKEN} ."
            }
          } {code}
          When looking at the pipeline output I can see the trailing "." is being removed from the docker.build step
          {code:java}
          + docker build -t my-image:dev --build-arg VAULT_TOKEN=<token>
          "docker build" requires exactly 1 argument.
          See 'docker build --help'.

          Usage: docker build [OPTIONS] PATH | URL | - {code}

          Gene Gaddy added a comment -

          If anyone has the same problem I was able to get around it by putting the commands into a shell script and just calling that

          more build_image.sh                                                                                                 [17:26:11]
          #!/bin/bash
          docker build -t $1 --build-arg $2=$3 . 
              stage('Build MOTU image') {
                        steps{
                          sh """./build_image.sh my-image:dev VAULT_TOKEN ${VAULT_TOKEN}"""
                        }
                      } 

          Gene Gaddy added a comment - If anyone has the same problem I was able to get around it by putting the commands into a shell script and just calling that more build_image.sh [17:26:11] #!/bin/bash docker build -t $1 --build-arg $2=$3 . stage( 'Build MOTU image' ) { steps{ sh """./build_image.sh my-image:dev VAULT_TOKEN ${VAULT_TOKEN}" "" } }
          Oleg Nenashev made changes -
          Component/s New: docker-workflow-plugin [ 20625 ]
          Component/s Original: docker-plugin [ 18724 ]
          Oleg Nenashev made changes -
          Assignee Original: Nicolas De Loof [ ndeloof ]

          Yuri added a comment -

          This is not a bug.

          Your variable VAULT_TOKEN probably contains new lines.

          You just need to trim it before passing to docker.build.

          See this: https://stackoverflow.com/questions/69122042/pass-to-docker-build-several-build-arg-arguments/69127696#69127696

          Yuri added a comment - This is not a bug. Your variable VAULT_TOKEN probably contains new lines. You just need to trim it before passing to docker.build. See this:  https://stackoverflow.com/questions/69122042/pass-to-docker-build-several-build-arg-arguments/69127696#69127696

            Unassigned Unassigned
            gene_gaddy Gene Gaddy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: