• Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Major Major
    • git-plugin
    • None

      I am trying to get Jenkins to build off a Git repository when tags following a particular naming appear or change (typically "release-*").

      I tried different ways, using refs/tags/release-* as Branch Specifier (in Branches to build), without any luck.

      Digging into the code, it seems that the DefaultBuildChooser only takes branches into consideration, not tags (save for some special case when polling a single branch, but then the tag is still not promoted as a candidate).

      Wouldn't it be useful to also allow to build off tags?

      If there is an alternative way, I'd be curious to hear that too.

          [JENKINS-9713] Poll and match tags on top of branches

          Mark Waite added a comment -

          Using git plugin 2.4.0, git client 1.18.0, and git parameter plugin 0.4.0, I was able to build from a tag parameter chosen from the list of tags known to the git repository.

          I used the following steps

          1. Define a new job JENKINS-9713-cannot-build-based-on-tags
          2. Use git://github.com/jenkinsci/git-client-plugin.git as the git SCM URL
          3. Parameterize the job, and add a Git parameter "TAG_TO_BUILD" of type "Tag" on branch origin/master with default value git-client-1.18.0
          4. Assign "Branches to build" the value "refs/tags/$TAG_TO_BUILD"
          5. Add an Xshell build step "git log -n 1" to show which commit was checked out in console output
          6. Run one build with the default value so that the parameter values can be populated
          7. Run a build choosing any one of the tags, confirm that is the build which is run

          Mark Waite added a comment - Using git plugin 2.4.0, git client 1.18.0, and git parameter plugin 0.4.0, I was able to build from a tag parameter chosen from the list of tags known to the git repository. I used the following steps Define a new job JENKINS-9713 -cannot-build-based-on-tags Use git://github.com/jenkinsci/git-client-plugin.git as the git SCM URL Parameterize the job, and add a Git parameter "TAG_TO_BUILD" of type "Tag" on branch origin/master with default value git-client-1.18.0 Assign "Branches to build" the value "refs/tags/$TAG_TO_BUILD" Add an Xshell build step "git log -n 1" to show which commit was checked out in console output Run one build with the default value so that the parameter values can be populated Run a build choosing any one of the tags, confirm that is the build which is run

          Code changed in jenkins
          User: Claudio Bley
          Path:
          src/main/java/hudson/plugins/git/util/GitUtils.java
          src/test/java/hudson/plugins/git/GitSCMTest.java
          http://jenkins-ci.org/commit/git-plugin/31fedce9c41c9006c886835e03c9fe825d49aba6
          Log:
          [FIXED JENKINS-09713] Consider tags when checking which branches to build

          When using multiple branch specifiers, the git plugin uses an advanced
          selection mechanism as defined in `getAdvancedCandidateRevisons` which
          does not consider tags from the repository, only normal branches.

          E.g. when using the following Branch specifiers:

          • refs/remotes/origin/${B}
          • refs/tags/${B}

          where B is a build parameter having a default value of "master" never
          causes any tag to be build, regardless of what the user chooses.

          Include the tags to complete the list of valid branches to find the best
          matching ref for the current build.

          Add testMultipleBranchesWithTags to GitSCMTest

          This test checks that for multiple branch specifications including some
          tag references, the build succeeds and selects the correct revision.

          Pull request #340

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Claudio Bley Path: src/main/java/hudson/plugins/git/util/GitUtils.java src/test/java/hudson/plugins/git/GitSCMTest.java http://jenkins-ci.org/commit/git-plugin/31fedce9c41c9006c886835e03c9fe825d49aba6 Log: [FIXED JENKINS-09713] Consider tags when checking which branches to build When using multiple branch specifiers, the git plugin uses an advanced selection mechanism as defined in `getAdvancedCandidateRevisons` which does not consider tags from the repository, only normal branches. E.g. when using the following Branch specifiers: refs/remotes/origin/${B} refs/tags/${B} where B is a build parameter having a default value of "master" never causes any tag to be build, regardless of what the user chooses. Include the tags to complete the list of valid branches to find the best matching ref for the current build. Add testMultipleBranchesWithTags to GitSCMTest This test checks that for multiple branch specifications including some tag references, the build succeeds and selects the correct revision. Pull request #340

          jbq added a comment -

          jbq added a comment - Fixed, see https://github.com/jenkinsci/git-plugin/pull/340

            jbq jbq
            theefer Sebastien Cevey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: