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

git-plugin should support tags in multibranch pipeline configurations

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

      Currently the git plugin doesn't seem to support tags in multi-branch builds.  It looks like this is because the ref prefixes are hard-coded. See: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java#L417

      This is similar to JENKINS-34395 but for the git plugin.  I'm creating a  separate issue because the causes and the fixes appear to be unrelated.

          [JENKINS-46207] git-plugin should support tags in multibranch pipeline configurations

          Mark Waite added a comment -

          Released in git plugin 3.6.0

          Mark Waite added a comment - Released in git plugin 3.6.0

          the solution does not work for me, I commented the problem to the PR: https://github.com/jenkinsci/git-plugin/pull/528

          Konstantin Ryakhovskiy added a comment - the solution does not work for me, I commented the problem to the PR:  https://github.com/jenkinsci/git-plugin/pull/528

          Konstantin Ryakhovskiy added a comment - - edited

          with git-plugin 3.6.2 tags are successfully discovered, however they are not automatically built.

          Output of the scan multibranch pipeline log:  

          Checking tag v0.10.0
          'Jenkinsfile' found
          Met criteria
          No automatic builds for v0.10.0
          

          the reason is that Multibranch Pipeline uses heads only to schedule automatic builds:
          https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/MultiBranchProject.java#L2151

          is it intended behaviour?

          Konstantin Ryakhovskiy added a comment - - edited with git-plugin 3.6.2 tags are successfully discovered, however they are not automatically built. Output of the scan multibranch pipeline log:   Checking tag v0.10.0 'Jenkinsfile' found Met criteria No automatic builds for v0.10.0 the reason is that Multibranch Pipeline uses heads only to schedule automatic builds: https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/MultiBranchProject.java#L2151 is it intended behaviour?

          kr

          It is intended behaviour... look a few lines further down: https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/MultiBranchProject.java#L2165

          • Some people may configure the Jenkinsfile to deploy to production for tags.
          • We cannot control the order in which tags will be built if multiple tags are discovered in the same indexing
          • As a result, building tags automatically would be risky.

          There is an extension point (which is hidden until you have some implementations) called BranchBuildStrategy and that can determine if you want to build tags automatically, but this would be opt-in behaviour.

          By default, tags will not be built. You must configure automatic building of tags... see https://github.com/jenkinsci/github-branch-source-plugin/pull/158#issuecomment-332773194 and https://github.com/AngryBytes/jenkins-build-everything-strategy-plugin for starting points if you want to build tags automatically

          Stephen Connolly added a comment - kr It is intended behaviour... look a few lines further down: https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/MultiBranchProject.java#L2165 Some people may configure the Jenkinsfile to deploy to production for tags. We cannot control the order in which tags will be built if multiple tags are discovered in the same indexing As a result, building tags automatically would be risky. There is an extension point (which is hidden until you have some implementations) called BranchBuildStrategy and that can determine if you want to build tags automatically, but this would be opt-in behaviour. By default, tags will not be built. You must configure automatic building of tags... see https://github.com/jenkinsci/github-branch-source-plugin/pull/158#issuecomment-332773194  and https://github.com/AngryBytes/jenkins-build-everything-strategy-plugin  for starting points if you want to build tags automatically

          Bill Hamilton added a comment -

          stephenconnolly markwaite If I kick off a tag build, do you know how in the Jenkinsfile I can detect that it is a tag build?

          Bill Hamilton added a comment - stephenconnolly markwaite If I kick off a tag build, do you know how in the Jenkinsfile I can detect that it is a tag build?

          The env.TAG_NAME will be non-null when building a tag

          Stephen Connolly added a comment - The env.TAG_NAME will be non-null when building a tag

          Mark Waite added a comment -

          hamiltb if you need to determine the list of all tags which point at a specific SHA1, you can use the shell command:

          git tag --points-at HEAD

          The env.TAG_NAME which stephenconnolly references should be more reliable than the points-at shell trick, since it is set inside the plugins, rather than being guessed from the condition of the repository.

          Mark Waite added a comment - hamiltb if you need to determine the list of all tags which point at a specific SHA1, you can use the shell command: git tag --points-at HEAD The env.TAG_NAME which stephenconnolly references should be more reliable than the points-at shell trick, since it is set inside the plugins, rather than being guessed from the condition of the repository.

          Bill Hamilton added a comment - - edited

          stephenconnolly markewaite

          env.TAG_NAME doesnt exist in a tag build. I printed out all envars:

          @NonCPS
          def printParams() {
          env.getEnvironment().each { name, value -> println "$name : $value" }
          }
          printParams()

          and TAG_NAME isnt there.

          Bill Hamilton added a comment - - edited stephenconnolly markewaite env.TAG_NAME doesnt exist in a tag build. I printed out all envars: @NonCPS def printParams() { env.getEnvironment().each { name, value -> println "$name : $value" } } printParams() and TAG_NAME isnt there.

          What version of Branch API? TAG_NAME was added in 2.0.11

          Stephen Connolly added a comment - What version of Branch API? TAG_NAME was added in 2.0.11

          Bill Hamilton added a comment -

          Yep, works good now, thanks!

          Bill Hamilton added a comment - Yep, works good now, thanks!

            stephenconnolly Stephen Connolly
            kbrowder Kevin Browder
            Votes:
            3 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: