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

Does not spawn build if a branch refers to the same SHA1 as another already built branch

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Won't Fix
    • Component/s: git-plugin
    • Labels:
      None
    • Environment:
      git plugin version 2.2.0
      jenkins 1.509.2
    • Similar Issues:

      Description

      When git plugin branch is configured for tracking multiple branches (like '*' or 'origin/prefix.'), it looks like it ignores branches referring to the same SHA1 as another already built branch.

      For example, if master branch is already built, then none of the following commands will trigger a build:
      git branch release master
      git branch prevrelease master~20
      git checkout prevrelease; git reset --hard master~10

      This behaviour prevents me from creating jobs that for example:

      • use "Conditional Trigger" plugin to spawn another job when new branch is created (or updated);
      • or mirror the repository to another location.

      On the other hand, the current behaviour (of ignoring already built SHA1 regardless of the branch on which it was built) is sensible and probably suitable for most users.

      So I think it would be nice if git plugin had some configuration option that would consider both SHA1 and the branch name to decide if build is needed. I guess it should be a quite simple check to implement: if previous SHA1 of a branch does not exist or it is different than current SHA1 of the branch, then spawn a build.
      Would it be possible to add such an option?

      Thank you in advance,
      Robert

        Attachments

          Issue Links

            Activity

            Hide
            robbl Robert Luberda added a comment -
            Show
            robbl Robert Luberda added a comment - Oh, I'm not the only one who want this feature, see https://issues.jenkins-ci.org/browse/JENKINS-11337?focusedCommentId=159670&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-159670 and other comments in that JIRA report
            Hide
            kuon Nicolas Goy added a comment -

            I have the same problem.

            I added two branches under "Branches to build", "/develop" and "/staging".

            When I push changes to develop, a build is triggered. After that if I do:

            git checkout staging
            git merge develop
            git push

            A new build is not triggered.

            I use the conditional trigger plugin to have different test suites and post build hook.

            Show
            kuon Nicolas Goy added a comment - I have the same problem. I added two branches under "Branches to build", " /develop" and " /staging". When I push changes to develop, a build is triggered. After that if I do: git checkout staging git merge develop git push A new build is not triggered. I use the conditional trigger plugin to have different test suites and post build hook.
            Hide
            gustavokambara Gustavo Kambara added a comment - - edited

            Hello,

            While I was reading some JIRA ticket, I found the non-official Jenkins plugin Git Chooser Build Branches, which defines a build branch strategy that allows Jenkins to build the same commit that was built previously, considering a different branch.

            I am going to describe step-by-step how to configure, from webhook (Bitbucket) to the job configuration, in case someone else is trying to achieve the same goals.

            1. Install the following Jenkins plugins:

            2. On Bitbucket:

            • Access your repository settings
            • Access Webhooks -> Add Webhook
            • In URL, you should inform: YOUR_JENKINS_URL/bitbucket-hook/. Note that the trailing slash is required.
            • Configure the remaining fields as you wish

            3. On Jenkins:

            • In your job, mark "This build is parameterized"
            • Add a string parameter BRANCH with the wildcard that you want, say origin/*.
            • Configure your SCM and in "Branches to build", inform the same parameter specified before. In our case, $BRANCH.
            • In Git "Additional Behaviours", add "Strategy for choosing what to build", selecting "Build branches". Also, add "Force polling using workspace".
            • In "Build Triggers", check "Build when a change is pushed to BitBucket".

            That's it. When you push something in your repository (branch creation or push in existing branches), the job will be triggered.

            This build strategy could be included in Git plugin, so we have centralized configuration.

            Show
            gustavokambara Gustavo Kambara added a comment - - edited Hello, While I was reading some JIRA ticket, I found the non-official Jenkins plugin Git Chooser Build Branches , which defines a build branch strategy that allows Jenkins to build the same commit that was built previously, considering a different branch. I am going to describe step-by-step how to configure, from webhook (Bitbucket) to the job configuration, in case someone else is trying to achieve the same goals. 1. Install the following Jenkins plugins: Git Git Chooser Build Branches - you'll have to clone the repository, compile (maven) and install manually. Bitbucket 2. On Bitbucket: Access your repository settings Access Webhooks -> Add Webhook In URL, you should inform: YOUR_JENKINS_URL/bitbucket-hook/. Note that the trailing slash is required. Configure the remaining fields as you wish 3. On Jenkins: In your job, mark "This build is parameterized" Add a string parameter BRANCH with the wildcard that you want, say origin/*. Configure your SCM and in "Branches to build", inform the same parameter specified before. In our case, $BRANCH. In Git "Additional Behaviours", add "Strategy for choosing what to build", selecting "Build branches". Also, add "Force polling using workspace". In "Build Triggers", check "Build when a change is pushed to BitBucket". That's it. When you push something in your repository (branch creation or push in existing branches), the job will be triggered. This build strategy could be included in Git plugin, so we have centralized configuration.
            Hide
            markewaite Mark Waite added a comment -

            This behavior is deeply ingrained in the git plugin. Changing it would break many, many use cases. Won't fix.

            Show
            markewaite Mark Waite added a comment - This behavior is deeply ingrained in the git plugin. Changing it would break many, many use cases. Won't fix.

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              robbl Robert Luberda
              Votes:
              4 Vote for this issue
              Watchers:
              9 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: