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

Scanning branches for freestyle project deletes all build history

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Critical
    • Resolution: Unresolved
    • Environment:
    • Similar Issues:

      Description

      A section "com.github.mjdetullio.jenkins.plugins.multibranch.BranchProjectProperty" can appear in the template config.xml file after certain configuration operations. When this section is present, running branch indexing will delete the job execution history under all branches.

      This section doesn't always exist. One way to create it is to enable "Ant/ivy Artifactory integration", which will create the section. Disabling the "Ant/ivy Artifactory integration" doesn't help - the section will still be present and will still cause the error.

      This wast not happening with Multibranch 0.5.2, BranchApi 1.11.1, and SCM 1.3. After upgrading, existing jobs had their jobs deleted when reindexed. I was able to come up with a repro case with a new project:

      Repro steps:

      • Create a new freestyle multibranch project
      • Add a GitHub source and save (my source had 2 branches in it, doesn't really matter)
      • Branches will build successfully (there are no build steps)
      • Scan Project / Run Now - No change to the history
      • Here's where the problems start
      • Configure the project
      • Check the box for "Ant/Ivy-Artifactory Integration"
      • Click Apply
      • Uncheck the box for "Ant/Ivy-Artifactory Integration"
      • Click Save
      • Build history and last success are gone
      • Run some builds. History and success/fail are back.
      • Scan Project / Run now
      • Build history and last success are gone again
      • Edit the "template/config.xml" file for this job
      • A new section has appeared:
        <com.github.mjdetullio.jenkins.plugins.multibranch.BranchProjectProperty plugin="multi-branch-project-plugin@0.6">
          <branch plugin="branch-api@2.0.7">
            <sourceId>unknown</sourceId>
            <head plugin="scm-api@2.0.7">
              <name>template</name>
            </head>
            <scm class="hudson.scm.NullSCM"/>
            <properties/>
            <actions/>
          </branch>
        </com.github.mjdetullio.jenkins.plugins.multibranch.BranchProjectProperty>
        
      • To fix the problem
      • Delete this section.
      • Reload configuration from disk
      • Job history has returned, but the last success is still missing.
      • Build the jobs to get another success
      • Scan project / Run now
      • Job history and last success are present

        Attachments

          Activity

          Hide
          fmiedniak Florian Miedniak added a comment -

          We experienced the same problem in our Jenkins setup. Though, we made some additional observations:

          • After configuring Artifactory plugin and doing a project scan, a folder “template” is created in subfolder “branches” of Multibranch project folder on Jenkins master.
          • The folder contains  a file “nextBuildNumber”.
          • The complete history for the Multibranch is gone now and the job doesn’t work anymore.
          • If the folder is deleted manually, the history is available again but a new scan will create the folder “template” once again and so on…
          Show
          fmiedniak Florian Miedniak added a comment - We experienced the same problem in our Jenkins setup. Though, we made some additional observations: After configuring Artifactory plugin and doing a project scan, a folder “template” is created in subfolder “branches” of Multibranch project folder on Jenkins master. The folder contains  a file “nextBuildNumber”. The complete history for the Multibranch is gone now and the job doesn’t work anymore. If the folder is deleted manually, the history is available again but a new scan will create the folder “template” once again and so on…
          Hide
          s_hildwein Samuel Hildwein added a comment -

          The problem also occurs after Jenkins update. So after every update workaround has to be done.

          Show
          s_hildwein Samuel Hildwein added a comment - The problem also occurs after Jenkins update. So after every update workaround has to be done.
          Hide
          fwr Frank Racis added a comment -

          I found the root of the problem and have a quick hack to fix it.

          In TemplateDrivenBranchProjectFactory, getBranch will add a Branch to the project if not found.    However, getBranch is getting called for the "template" project.   Adding the Branch to the template problem causes the problems we've been seeing.

          Here is a diff that will stop adding the branch to the template project:

          diff --git a/src/main/java/com/github/mjdetullio/jenkins/plugins/multibranch/TemplateDrivenBranchProjectFactory.java b/src/main/java/com/github/mjdetullio/jenkins/plugins/multibranch/TemplateDrivenBranchProjectFactory.java
          index c2d5939..81b925c 100644
          --- a/src/main/java/com/github/mjdetullio/jenkins/plugins/multibranch/TemplateDrivenBranchProjectFactory.java
          +++ b/src/main/java/com/github/mjdetullio/jenkins/plugins/multibranch/TemplateDrivenBranchProjectFactory.java
          @@ -73,6 +73,13 @@ public abstract class TemplateDrivenBranchProjectFactory<P extends AbstractProje
          * or that it will be converted to Branch.Dead and the guessed values for sourceId and properties won't matter. */
          if (property == null) {
          + // Don't try to set a branch on the template folder,
          + // otherwise all your history will disappear.
          + // There might be nicer fix, but this works
          + if (project.getName().equals("template")){
          + LOGGER.log(Level.INFO, "Skip branch setting for template " + project.getFullName());
          + return null;
          + }
          Branch branch = new Branch("unknown", new SCMHead(project.getDisplayName()), project.getScm(),
          Collections.<BranchProperty>emptyList());
          setBranch(project, branch);
          
          Show
          fwr Frank Racis added a comment - I found the root of the problem and have a quick hack to fix it. In TemplateDrivenBranchProjectFactory, getBranch will add a Branch to the project if not found.    However, getBranch is getting called for the "template" project.   Adding the Branch to the template problem causes the problems we've been seeing. Here is a diff that will stop adding the branch to the template project: diff --git a/src/main/java/com/github/mjdetullio/jenkins/plugins/multibranch/TemplateDrivenBranchProjectFactory.java b/src/main/java/com/github/mjdetullio/jenkins/plugins/multibranch/TemplateDrivenBranchProjectFactory.java index c2d5939..81b925c 100644 --- a/src/main/java/com/github/mjdetullio/jenkins/plugins/multibranch/TemplateDrivenBranchProjectFactory.java +++ b/src/main/java/com/github/mjdetullio/jenkins/plugins/multibranch/TemplateDrivenBranchProjectFactory.java @@ -73,6 +73,13 @@ public abstract class TemplateDrivenBranchProjectFactory<P extends AbstractProje * or that it will be converted to Branch.Dead and the guessed values for sourceId and properties won't matter. */ if (property == null ) { + // Don't try to set a branch on the template folder, + // otherwise all your history will disappear. + // There might be nicer fix, but this works + if (project.getName().equals( "template" )){ + LOGGER.log(Level.INFO, "Skip branch setting for template " + project.getFullName()); + return null ; + } Branch branch = new Branch( "unknown" , new SCMHead(project.getDisplayName()), project.getScm(), Collections.<BranchProperty>emptyList()); setBranch(project, branch);
          Hide
          michalmanko Michał Mańko added a comment -

          I have the same problem when I enable Gradle-Artifactory Integration.

          Show
          michalmanko Michał Mańko added a comment - I have the same problem when I enable Gradle-Artifactory Integration.

            People

            Assignee:
            mjdetullio Matthew DeTullio
            Reporter:
            fwr Frank Racis
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated: