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

Cannot give build-arg or environment variable to docker.build

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • docker-workflow-plugin
    • None
    • docker-ce-17.06.0

      I have a Dockerfile like this:

      ARG REGISTRY_URL=machine:5000
      ARG PI_VERSION=0.4
      FROM ${REGISTRY_URL}/java:${PI_VERSION}

      I cannot set REGISTRY_URL, neither by build-arg nor environment variable.

      In jenkinsfile:
      def dockerImage = docker.build "${VAR_DOCKER.registry}${item.name}:${item.versionDocker}"
      Even with withEnv, it does not recognize new variable.

          [JENKINS-48042] Cannot give build-arg or environment variable to docker.build

          Paul "TBBle" Hampson added a comment - - edited

          Your example code-line does appear to attempt to set the build-arg. It should have been something like

          def dockerImage = docker.build("${VAR_DOCKER.registry}${item.name}:${item.versionDocker}", '--build-arg REGISTRY_URL')

          and then it will use the REGISTRY_URL value you set with withEnv.

          Alternatively, 

          def dockerImage = docker.build("${VAR_DOCKER.registry}${item.name}:${item.versionDocker}", "--build-arg REGISTRY_URL=${GroovyVariableWithRegistryOverride}") 

          would not require you to export the override value into the shell environment with withEnv.

          See docker build in the Docker Documentation for reference. Although the docs are for the current version, and this issue was lodged against a (now) 5-year-old Docker release, this behaviour shouldn't have changed.

          Paul "TBBle" Hampson added a comment - - edited Your example code-line does appear to attempt to set the build-arg. It should have been something like def dockerImage = docker.build( "${VAR_DOCKER.registry}${item.name}:${item.versionDocker}" , '--build-arg REGISTRY_URL' ) and then it will use the REGISTRY_URL value you set with withEnv . Alternatively,  def dockerImage = docker.build( "${VAR_DOCKER.registry}${item.name}:${item.versionDocker}" , "--build-arg REGISTRY_URL=${GroovyVariableWithRegistryOverride}" ) would not require you to export the override value into the shell environment with withEnv . See  docker build in the Docker Documentation  for reference. Although the docs are for the current version, and this issue was lodged against a (now) 5-year-old Docker release, this behaviour shouldn't have changed.

            Unassigned Unassigned
            antoinetran Antoine Tran
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: