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

git-plugin should support tags in multibranch pipeline configurations

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • git-plugin
    • None

    Description

      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.

      Attachments

        Issue Links

          Activity

            kbrowder Kevin Browder created issue -
            markewaite Mark Waite made changes -
            Field Original Value New Value
            Assignee Mark Waite [ markewaite ]
            kbrowder Kevin Browder added a comment -

            Oh that's weird JIRA said it lost this when i created it, apparently it didn't, marking as duplicate.  My Applologies

            kbrowder Kevin Browder added a comment - Oh that's weird JIRA said it lost this when i created it, apparently it didn't, marking as duplicate.  My Applologies
            kbrowder Kevin Browder made changes -
            Link This issue duplicates JENKINS-46208 [ JENKINS-46208 ]
            kbrowder Kevin Browder made changes -
            Resolution Duplicate [ 3 ]
            Status Open [ 1 ] Closed [ 6 ]

            Prefer this one to JENKINS-46208 as this has a better description

            stephenconnolly Stephen Connolly added a comment - Prefer this one to JENKINS-46208 as this has a better description
            stephenconnolly Stephen Connolly made changes -
            Resolution Duplicate [ 3 ]
            Status Closed [ 6 ] Reopened [ 4 ]
            stephenconnolly Stephen Connolly made changes -
            Link This issue is duplicated by JENKINS-46208 [ JENKINS-46208 ]
            stephenconnolly Stephen Connolly made changes -
            Link This issue duplicates JENKINS-46208 [ JENKINS-46208 ]

            Nothing to do with ref-specs, the actual impl is more complex.

            My initial stab at an implementation is https://github.com/jenkinsci/git-plugin/pull/528

            Will need testing before we can merge... will likely need changes in branch-api to prevent build storms unless I was good at anticipating the needs of tags

            stephenconnolly Stephen Connolly added a comment - Nothing to do with ref-specs, the actual impl is more complex. My initial stab at an implementation is https://github.com/jenkinsci/git-plugin/pull/528 Will need testing before we can merge... will likely need changes in branch-api to prevent build storms unless I was good at anticipating the needs of tags
            stephenconnolly Stephen Connolly made changes -
            Remote Link This issue links to "PR#528 (Web Link)" [ 17611 ]
            stephenconnolly Stephen Connolly added a comment - https://github.com/jenkinsci/branch-api-plugin/commit/cf848af4addf33f0aae9c86149fc0cfd1fee5c82#diff-b347159a8a8075d4e700065f8668b804R1811 Looks like a was good at anticipating the needs of tags... ok just requires testing!
            stephenconnolly Stephen Connolly made changes -
            Status Reopened [ 4 ] In Progress [ 3 ]
            stephenconnolly Stephen Connolly made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            stephenconnolly Stephen Connolly made changes -
            Assignee Stephen Connolly [ stephenconnolly ]

            Manual testing looks good!

            stephenconnolly Stephen Connolly added a comment - Manual testing looks good!
            stephenconnolly Stephen Connolly made changes -
            Link This issue is related to JENKINS-34395 [ JENKINS-34395 ]
            stephenconnolly Stephen Connolly made changes -
            Link This issue is duplicated by JENKINS-37050 [ JENKINS-37050 ]
            kbrowder Kevin Browder added a comment -

            Very cool, simpler than what I was thinking too, thanks

            kbrowder Kevin Browder added a comment - Very cool, simpler than what I was thinking too, thanks

            Code changed in jenkins
            User: Stephen Connolly
            Path:
            src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java
            src/main/java/jenkins/plugins/git/GitSCMSource.java
            src/main/java/jenkins/plugins/git/GitTagSCMHead.java
            src/main/java/jenkins/plugins/git/GitTagSCMRevision.java
            src/main/java/jenkins/plugins/git/traits/BranchDiscoveryTrait.java
            src/main/java/jenkins/plugins/git/traits/TagDiscoveryTrait.java
            src/main/resources/jenkins/plugins/git/traits/Messages.properties
            src/main/resources/jenkins/plugins/git/traits/TagDiscoveryTrait/config.jelly
            src/main/resources/jenkins/plugins/git/traits/TagDiscoveryTrait/help.html
            src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java
            http://jenkins-ci.org/commit/git-plugin/837ae6424c7636b6f7aaabbe8337ae3a2c053d0a
            Log:
            JENKINS-46207 Initial implementation, if lucky this is complete

            • I suspect there are additional changes required before can merge for git
            • I suspect there are additional changes required to branch-api before safe to merge for users
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Stephen Connolly Path: src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java src/main/java/jenkins/plugins/git/GitSCMSource.java src/main/java/jenkins/plugins/git/GitTagSCMHead.java src/main/java/jenkins/plugins/git/GitTagSCMRevision.java src/main/java/jenkins/plugins/git/traits/BranchDiscoveryTrait.java src/main/java/jenkins/plugins/git/traits/TagDiscoveryTrait.java src/main/resources/jenkins/plugins/git/traits/Messages.properties src/main/resources/jenkins/plugins/git/traits/TagDiscoveryTrait/config.jelly src/main/resources/jenkins/plugins/git/traits/TagDiscoveryTrait/help.html src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java http://jenkins-ci.org/commit/git-plugin/837ae6424c7636b6f7aaabbe8337ae3a2c053d0a Log: JENKINS-46207 Initial implementation, if lucky this is complete I suspect there are additional changes required before can merge for git I suspect there are additional changes required to branch-api before safe to merge for users

            Code changed in jenkins
            User: Mark Waite
            Path:
            src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java
            src/main/java/jenkins/plugins/git/GitSCMSource.java
            src/main/java/jenkins/plugins/git/GitTagSCMHead.java
            src/main/java/jenkins/plugins/git/GitTagSCMRevision.java
            src/main/java/jenkins/plugins/git/traits/BranchDiscoveryTrait.java
            src/main/java/jenkins/plugins/git/traits/TagDiscoveryTrait.java
            src/main/resources/jenkins/plugins/git/traits/Messages.properties
            src/main/resources/jenkins/plugins/git/traits/TagDiscoveryTrait/config.jelly
            src/main/resources/jenkins/plugins/git/traits/TagDiscoveryTrait/help.html
            src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java
            http://jenkins-ci.org/commit/git-plugin/fe5a3f42a1f7e6ceb978ee2e603a1068dfeba970
            Log:
            Merge pull request #528 from stephenc/jenkins-46207

            JENKINS-46207 Enable tag discovery

            Compare: https://github.com/jenkinsci/git-plugin/compare/35745f2e3f81...fe5a3f42a1f7

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Mark Waite Path: src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java src/main/java/jenkins/plugins/git/GitSCMSource.java src/main/java/jenkins/plugins/git/GitTagSCMHead.java src/main/java/jenkins/plugins/git/GitTagSCMRevision.java src/main/java/jenkins/plugins/git/traits/BranchDiscoveryTrait.java src/main/java/jenkins/plugins/git/traits/TagDiscoveryTrait.java src/main/resources/jenkins/plugins/git/traits/Messages.properties src/main/resources/jenkins/plugins/git/traits/TagDiscoveryTrait/config.jelly src/main/resources/jenkins/plugins/git/traits/TagDiscoveryTrait/help.html src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java http://jenkins-ci.org/commit/git-plugin/fe5a3f42a1f7e6ceb978ee2e603a1068dfeba970 Log: Merge pull request #528 from stephenc/jenkins-46207 JENKINS-46207 Enable tag discovery Compare: https://github.com/jenkinsci/git-plugin/compare/35745f2e3f81...fe5a3f42a1f7
            chris5287 Chris Stylianou made changes -
            Link This issue is related to JENKINS-47254 [ JENKINS-47254 ]
            markewaite Mark Waite added a comment -

            Released in git plugin 3.6.0

            markewaite Mark Waite added a comment - Released in git plugin 3.6.0
            markewaite Mark Waite made changes -
            Resolution Fixed [ 1 ]
            Status In Review [ 10005 ] Resolved [ 5 ]

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

            kr 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
            kr 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 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

            stephenconnolly 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
            hamiltb 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?

            hamiltb 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

            stephenconnolly Stephen Connolly added a comment - The env.TAG_NAME will be non-null when building a tag
            markewaite 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.

            markewaite 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.
            hamiltb 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.

            hamiltb 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

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

            Yep, works good now, thanks!

            hamiltb Bill Hamilton added a comment - Yep, works good now, thanks!
            stephenconnolly Stephen Connolly made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

            People

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

              Dates

                Created:
                Updated:
                Resolved: