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

Recreating projects using jenkins-cli generates "cannot create a build with number" error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • cli
    • None
    • Jenkins v2.0

      I am using the Jenkins CLI jar to recreate projects based on a tempate project.

      The process is as follows

      • Calls 'get-job' to check if the job exists
      • If job exists calls 'delete-job' to remove the project
      • Calls 'create-job' to create the project (using the same job name as the one deleted)

      'create-job' simply uses the XML job description from the template job with various properties altered (job name, env variables etc.).

      The issue seems to occur if the job already exists and has been run multiple times before being deleted and recreated.

      So, if the job is initially created and runs 32 times before being deleted and recreated, the next time this (new) job is run, it generates this error

      java.lang.IllegalStateException: cannot create a build with number 1 since that (or higher) is already in use among [32]
      at jenkins.model.lazy.AbstractLazyLoadRunMap.proposeNewNumber(AbstractLazyLoadRunMap.java:373)
      at hudson.model.RunMap.put(RunMap.java:191)
      at jenkins.model.lazy.LazyBuildMixIn.newBuild(LazyBuildMixIn.java:176)
      at hudson.model.AbstractProject.newBuild(AbstractProject.java:1018)
      at hudson.model.AbstractProject.createExecutable(AbstractProject.java:1209)
      at hudson.model.AbstractProject.createExecutable(AbstractProject.java:144)
      at hudson.model.Executor$1.call(Executor.java:364)
      at hudson.model.Executor$1.call(Executor.java:346)
      at hudson.model.Queue._withLock(Queue.java:1371)
      at hudson.model.Queue.withLock(Queue.java:1232)
      at hudson.model.Executor.run(Executor.java:346)

      This will continue to happen until we run the new job 33 times, at which point the build number is >32 and the job can successfully start.

      As the job is deleted, I would expect the cached build number to have been deleted also.

            Unassigned Unassigned
            leewinder Lee Winder
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: