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

TAG_NAME is not populated in declarative multibranch pipeline

      I configured a multibranch pipeline to check out via git, discover branches, discover tags and the added clone behaviour to fetch tags.

      However I can't use the when condition with tags as outlined here (https://jenkins.io/blog/2018/05/16/pipelines-with-git-tags/). According to the docs (https://jenkins.io/doc/book/pipeline/syntax/#when) when depends on the variable TAG_NAME which I assume should be set by Jenkins. But both  params.TAG_NAME, env.TAG_NAME are null.

      Thus my when condition 'when { tag "" }' never triggers.

          [JENKINS-58751] TAG_NAME is not populated in declarative multibranch pipeline

          Mark Waite added a comment - - edited

          Please provide more details on the multibranch pipeline that you created. Preferably, provide step-by-step instructions that someone else can use to duplicate the problem.

          You said:

          I configured a multibranch pipeline to check out via git, discover branches, discover tags and the added clone behaviour to fetch tags.

          You didn't say:

          • What version of the git client plugin, git plugin, github branch source, bitbucket branch source, Gitea, pipeline, and other plugins you're using
          • Which SCM implementation you used to create the multibranch pipeline (git, GitHub branch source, Bitbucket, Gitea, something else)
          • What other options you configured as part of defining the multibranch pipeline
          • The configuration file ( config.xml ) of the multibranch pipeline that is showing the problem

          Assumptions I made:

          • Windows 10 means that the Jenkins server is running on Windows 10.
          • Git for Windows 2.22 is being used on the Windows 10 Jenkins server. I don't see anything that hints this is somehow connected to a specific version of command line git on Windows, so I assumed the version I have installed on my Windows computer
          • Java 8 as provided by AdoptOpenJDK, since that is what I have installed on my Windows computer now that Oracle JDK requires a license purchase from Oracle for commercial use
          • Latest releases of all the relevant plugins
          • GitHub as the provider for the multibranch pipeline definition (not git, not Bitbucket, and not Gitea)

          Mark Waite added a comment - - edited Please provide more details on the multibranch pipeline that you created. Preferably, provide step-by-step instructions that someone else can use to duplicate the problem. You said: I configured a multibranch pipeline to check out via git, discover branches, discover tags and the added clone behaviour to fetch tags. You didn't say: What version of the git client plugin, git plugin, github branch source, bitbucket branch source, Gitea, pipeline, and other plugins you're using Which SCM implementation you used to create the multibranch pipeline (git, GitHub branch source, Bitbucket, Gitea, something else) What other options you configured as part of defining the multibranch pipeline The configuration file ( config.xml ) of the multibranch pipeline that is showing the problem Assumptions I made: Windows 10 means that the Jenkins server is running on Windows 10. Git for Windows 2.22 is being used on the Windows 10 Jenkins server. I don't see anything that hints this is somehow connected to a specific version of command line git on Windows, so I assumed the version I have installed on my Windows computer Java 8 as provided by AdoptOpenJDK, since that is what I have installed on my Windows computer now that Oracle JDK requires a license purchase from Oracle for commercial use Latest releases of all the relevant plugins GitHub as the provider for the multibranch pipeline definition (not git, not Bitbucket, and not Gitea)

          John Doe added a comment -

          Yes, thank you, you're assumptions are mostly correct. It turned out the problem is that 'TAG_NAME' is only populated when the build is triggered because of a tag. In order to get builds triggered by tags one needs the Basic Branch Build Strategies plugin (https://wiki.jenkins.io/display/JENKINS/Basic+Branch+Build+Strategies+Plugin). I think the docs on the when condition (https://jenkins.io/doc/book/pipeline/syntax/#when)  could be improved upon by mentioning this.

          John Doe added a comment - Yes, thank you, you're assumptions are mostly correct. It turned out the problem is that 'TAG_NAME' is only populated when the build is triggered because of a tag. In order to get builds triggered by tags one needs the Basic Branch Build Strategies plugin ( https://wiki.jenkins.io/display/JENKINS/Basic+Branch+Build+Strategies+Plugin). I think the docs on the when condition ( https://jenkins.io/doc/book/pipeline/syntax/#when)   could be improved upon by mentioning this.

          Mark Waite added a comment - - edited

          Thanks for the suggestion on the documentation. I've added it to my "Jenkins Git Use Cases" document to remind me of things that need to be documented and where they need to be documented.

          If you'd like to submit a pull request, the documentation is open for contributions. The GitHub interface makes it easy to contribute even without cloning or building locally. Refer to the when directive in the pipeline syntax.

          Mark Waite added a comment - - edited Thanks for the suggestion on the documentation. I've added it to my " Jenkins Git Use Cases " document to remind me of things that need to be documented and where they need to be documented. If you'd like to submit a pull request, the documentation is open for contributions. The GitHub interface makes it easy to contribute even without cloning or building locally. Refer to the when directive in the pipeline syntax .

            Unassigned Unassigned
            jenkinsuser12345678 John Doe
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: