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

Error on docker image name: Name must follow the pattern '^[a-zA-Z0-9]+((\.|_|__|-+)[a-zA-Z0-9]+)*$'

      After upgrading jenkins version from 2.221 to 2.337. I am facing issue while build docker image. Here is my docker build part which is failing.

      ```

      stage 'Folder Checkout'
      sh 'pwd'

      stage 'Docker build'
      docker.build('${RepoName}','--no-cache --build-arg ssh_prv_key="$(cat ~/.ssh/commons-js)" --build-arg ssh_pub_key="$(cat ~/.ssh/commons-js.pub)" -f "${FolderName}Dockerfile" "${FolderName}"')
      //docker.build('${RepoName}','--no-cache --build-arg ssh_prv_key="$(cat ~/.ssh/commons-py-js)" --build-arg ssh_pub_key="$(cat ~/.ssh/commons-py-js.pub)" -f "${FolderName}Dockerfile" "${FolderName}"')

      stage 'Docker push'
      docker.withRegistry('https://'+'${RepoUrl}', 'ecr:ap-south-1:fa8ea731-f30c-4ae3-a6ca-d9afb9c49eae') {
      docker.image('${RepoName}').push('latest')
      }

      }

      ````

      And here is the error occured

      [Pipeline] }[Pipeline] // node[Pipeline] End of PipelineERROR: Name must follow the pattern '^[a-zA-Z0-9]((\.||_|-)[a-zA-Z0-9]+)*$'
      at hudson.util.FormValidation._errorWithMarkup(FormValidation.java:268)
      at hudson.util.FormValidation.errorWithMarkup(FormValidation.java:254)
      at hudson.util.FormValidation.error(FormValidation.java:145)
      at hudson.util.FormValidation.error(FormValidation.java:170)
      at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.validateName(ImageNameValidator.java:289)
      at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.validateUserAndRepo(ImageNameValidator.java:115)
      at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.checkUserAndRepo(ImageNameValidator.java:141)
      at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator$checkUserAndRepo.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
      at org.jenkinsci.plugins.docker.workflow.Docker.check(Docker.groovy:100)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
      at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151)
      at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:91)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
      at org.jenkinsci.plugins.docker.workflow.Docker.build(Docker.groovy:87)
      at WorkflowScript.run(WorkflowScript:15)
      at __cps.transform__(Native Method)
      at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
      at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
      at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
      at com.cloudbees.groovy.cps.impl.LocalVariableBlock$LocalVariable.get(LocalVariableBlock.java:39)
      at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
      at com.cloudbees.groovy.cps.impl.LocalVariableBlock.evalLValue(LocalVariableBlock.java:28)
      at com.cloudbees.groovy.cps.LValueBlock$BlockImpl.eval(LValueBlock.java:55)
      at com.cloudbees.groovy.cps.LValueBlock.eval(LValueBlock.java:16)
      at com.cloudbees.groovy.cps.Next.step(Next.java:83)
      at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
      at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
      at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
      at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
      at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
      at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
      at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
      at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:403)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:97)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:315)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:279)
      at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
      at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
      Finished: FAILURE

          [JENKINS-67986] Error on docker image name: Name must follow the pattern '^[a-zA-Z0-9]+((\.|_|__|-+)[a-zA-Z0-9]+)*$'

          Logan Mzz added a comment -

          You are using single quotes which are NOT interpolated. Use double quotes and everything should be fine

          Logan Mzz added a comment - You are using single quotes which are NOT interpolated. Use double quotes and everything should be fine

          Our case is similar. We are using names like repo/namespace/app:tag
          causing:

          11:59:20 ERROR: Name must follow the pattern '^[a-zA-Z0-9]+((\.|_|__|-+)[a-zA-Z0-9]+)*$'
          11:59:20 ERROR: Name must follow the pattern '^[a-zA-Z0-9]+((\.|_|__|-+)[a-zA-Z0-9]+)*$'
          11:59:20 	at hudson.util.FormValidation._errorWithMarkup(FormValidation.java:268)
          11:59:20 	at hudson.util.FormValidation.errorWithMarkup(FormValidation.java:254)
          11:59:20 	at hudson.util.FormValidation.error(FormValidation.java:145)
          11:59:20 	at hudson.util.FormValidation.error(FormValidation.java:170)
          11:59:20 	at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.validateName(ImageNameValidator.java:289)
          11:59:20 	at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.validateUserAndRepo(ImageNameValidator.java:115)
          11:59:20 	at org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint.imageName(DockerRegistryEndpoint.java:317)
          11:59:20 	at com.cloudbees.dockerpublish.DockerBuilder.getRepo(DockerBuilder.java:252)
          11:59:20 	at com.cloudbees.dockerpublish.DockerBuilder$Perform.getImageTags(DockerBuilder.java:336)
          11:59:20 	at com.cloudbees.dockerpublish.DockerBuilder$Perform.exec(DockerBuilder.java:305)
          11:59:20 	at com.cloudbees.dockerpublish.DockerBuilder$Perform.access$100(DockerBuilder.java:291)
          11:59:20 	at com.cloudbees.dockerpublish.DockerBuilder.perform(DockerBuilder.java:262)
          

          looking at ImageNameValidator.java#L279 called in ImageNameValidator.java#L115 I assume args[1] returned by ImageNameValidator.java#L60 might contains a colon at the end according to ImageNameValidator.java#L89-L92:

                      } else if (tagIdx > 0) {
                          int start = slashIdx > 0 ? slashIdx + 1 : 0;
                          args[1] = userAndRepo.substring(start, tagIdx);
                          args[2] = userAndRepo.substring(tagIdx);
          

          where I thing the fix might be

          -               args[1] = userAndRepo.substring(start, tagIdx);
          +               args[1] = userAndRepo.substring(start, tagIdx  - 1);
          

          as we do not want the colon separator in image name for the validation. But I am not a Java coder, so I did not debug it. Just using code review.

          Oskar Mitrowski added a comment - Our case is similar. We are using names like repo/namespace/app:tag causing: 11:59:20 ERROR: Name must follow the pattern '^[a-zA-Z0-9]+((\.|_|__|-+)[a-zA-Z0-9]+)*$' 11:59:20 ERROR: Name must follow the pattern '^[a-zA-Z0-9]+((\.|_|__|-+)[a-zA-Z0-9]+)*$' 11:59:20 at hudson.util.FormValidation._errorWithMarkup(FormValidation.java:268) 11:59:20 at hudson.util.FormValidation.errorWithMarkup(FormValidation.java:254) 11:59:20 at hudson.util.FormValidation.error(FormValidation.java:145) 11:59:20 at hudson.util.FormValidation.error(FormValidation.java:170) 11:59:20 at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.validateName(ImageNameValidator.java:289) 11:59:20 at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.validateUserAndRepo(ImageNameValidator.java:115) 11:59:20 at org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint.imageName(DockerRegistryEndpoint.java:317) 11:59:20 at com.cloudbees.dockerpublish.DockerBuilder.getRepo(DockerBuilder.java:252) 11:59:20 at com.cloudbees.dockerpublish.DockerBuilder$Perform.getImageTags(DockerBuilder.java:336) 11:59:20 at com.cloudbees.dockerpublish.DockerBuilder$Perform.exec(DockerBuilder.java:305) 11:59:20 at com.cloudbees.dockerpublish.DockerBuilder$Perform.access$100(DockerBuilder.java:291) 11:59:20 at com.cloudbees.dockerpublish.DockerBuilder.perform(DockerBuilder.java:262) looking at ImageNameValidator.java#L279 called in ImageNameValidator.java#L115 I assume args [1] returned by ImageNameValidator.java#L60 might contains a colon at the end according to ImageNameValidator.java#L89-L92 : } else if (tagIdx > 0) { int start = slashIdx > 0 ? slashIdx + 1 : 0; args[1] = userAndRepo.substring(start, tagIdx); args[2] = userAndRepo.substring(tagIdx); where I thing the fix might be - args[1] = userAndRepo.substring(start, tagIdx); + args[1] = userAndRepo.substring(start, tagIdx - 1); as we do not want the colon separator in image name for the validation. But I am not a Java coder, so I did not debug it. Just using code review.

          egrist added a comment - - edited

          Have the same problem as omitrowski running Docker Commons Version 1.18, building with CloudBees Docker Build and Publish 1.3.3 running on Jenkins 2.336:

          ERROR: Name must follow the pattern '^[a-zA-Z0-9]+((\.|_|__|-+)[a-zA-Z0-9]+)*$'
          ERROR: Name must follow the pattern '^[a-zA-Z0-9]+((\.|_|__|-+)[a-zA-Z0-9]+)*$'
          	at hudson.util.FormValidation._errorWithMarkup(FormValidation.java:268)
          	at hudson.util.FormValidation.errorWithMarkup(FormValidation.java:254)
          	at hudson.util.FormValidation.error(FormValidation.java:145)
          	at hudson.util.FormValidation.error(FormValidation.java:170)
          	at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.validateName(ImageNameValidator.java:209)
          	at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.validateUserAndRepo(ImageNameValidator.java:105)
          	at org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint.imageName(DockerRegistryEndpoint.java:317)
          	at com.cloudbees.dockerpublish.DockerBuilder.getRepo(DockerBuilder.java:252)
          	at com.cloudbees.dockerpublish.DockerBuilder$Perform.getImageTags(DockerBuilder.java:336)
          	at com.cloudbees.dockerpublish.DockerBuilder$Perform.exec(DockerBuilder.java:305)
          	at com.cloudbees.dockerpublish.DockerBuilder$Perform.access$100(DockerBuilder.java:291)
          	at com.cloudbees.dockerpublish.DockerBuilder.perform(DockerBuilder.java:262)
          	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
          	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:814)
          	at hudson.model.Build$BuildExecution.build(Build.java:199)
          	at hudson.model.Build$BuildExecution.doRun(Build.java:164)
          	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:522)
          	at hudson.model.Run.execute(Run.java:1896)
          	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
          	at hudson.model.ResourceController.execute(ResourceController.java:101)
          	at hudson.model.Executor.run(Executor.java:442)
          Build step 'Docker Build and Publish' marked build as failure 

          Also using names like repo/namespace/app:tag

          egrist added a comment - - edited Have the same problem as omitrowski running Docker Commons Version 1.18, building with CloudBees Docker Build and Publish 1.3.3 running on Jenkins 2.336: ERROR: Name must follow the pattern '^[a-zA-Z0-9]+((\.|_|__|-+)[a-zA-Z0-9]+)*$' ERROR: Name must follow the pattern '^[a-zA-Z0-9]+((\.|_|__|-+)[a-zA-Z0-9]+)*$' at hudson.util.FormValidation._errorWithMarkup(FormValidation.java:268) at hudson.util.FormValidation.errorWithMarkup(FormValidation.java:254) at hudson.util.FormValidation.error(FormValidation.java:145) at hudson.util.FormValidation.error(FormValidation.java:170) at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.validateName(ImageNameValidator.java:209) at org.jenkinsci.plugins.docker.commons.credentials.ImageNameValidator.validateUserAndRepo(ImageNameValidator.java:105) at org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint.imageName(DockerRegistryEndpoint.java:317) at com.cloudbees.dockerpublish.DockerBuilder.getRepo(DockerBuilder.java:252) at com.cloudbees.dockerpublish.DockerBuilder$Perform.getImageTags(DockerBuilder.java:336) at com.cloudbees.dockerpublish.DockerBuilder$Perform.exec(DockerBuilder.java:305) at com.cloudbees.dockerpublish.DockerBuilder$Perform.access$100(DockerBuilder.java:291) at com.cloudbees.dockerpublish.DockerBuilder.perform(DockerBuilder.java:262) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:814) at hudson.model.Build$BuildExecution.build(Build.java:199) at hudson.model.Build$BuildExecution.doRun(Build.java:164) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:522) at hudson.model.Run.execute(Run.java:1896) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44) at hudson.model.ResourceController.execute(ResourceController.java:101) at hudson.model.Executor.run(Executor.java:442) Build step 'Docker Build and Publish' marked build as failure Also using names like repo/namespace/app:tag

          Ipi Kiiskinen added a comment -

          Is there any chance & plans to get this fixed?
          This has frozen some of our docker plugins.
          We can't install new plugins because of the dependecies to these plugins but newer versions. Upgrading them would break our builds.

          I'm not a coder, so can't say if proposed fix would fix the issue. But I hope some plugin contributor could revise it?

          Ipi Kiiskinen added a comment - Is there any chance & plans to get this fixed? This has frozen some of our docker plugins. We can't install new plugins because of the dependecies to these plugins but newer versions. Upgrading them would break our builds. I'm not a coder, so can't say if proposed fix would fix the issue. But I hope some plugin contributor could revise it?

          Mark Waite added a comment - - edited

          I don't think that there is any plan to change the definition of characters allowed in the container name, in part because the Docker documentation says:

          While the OCI Distribution Specification supports more than two slash-separated components, most registries only support two slash-separated components. For Docker's public registry, the path format is as follows:

          • [NAMESPACE/]REPOSITORY: The first, optional component is typically a user's or an organization's namespace. The second, mandatory component is the repository name. When the namespace is not present, Docker uses library as the default namespace.

          When Docker documentation says "most registries only support two slash-separated components", I think that means that a container name should not contain more than one "/". That "/" separates the namespace from the repository.

          Mark Waite added a comment - - edited I don't think that there is any plan to change the definition of characters allowed in the container name, in part because the Docker documentation says: While the OCI Distribution Specification supports more than two slash-separated components, most registries only support two slash-separated components. For Docker's public registry, the path format is as follows: [NAMESPACE/] REPOSITORY: The first, optional component is typically a user's or an organization's namespace. The second, mandatory component is the repository name. When the namespace is not present, Docker uses library as the default namespace. When Docker documentation says "most registries only support two slash-separated components", I think that means that a container name should not contain more than one "/". That "/" separates the namespace from the repository.

            vjuranek vjuranek
            vinu1998 Vinamra mittal
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: