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

Trigger fails to build with "Null value not allowed as an environment variable: GIT_BRANCH" error

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • Ubuntu server, Jenkins 1.451, Gerrit Trigger 2.4.0, Git Plugin 1.1.15

      When a build is started by the Gerrit Trigger, it always fails with the error and
      stack track pasted below:

      Manually triggered by user admin for Gerrit: http://localhost:8080/79
      Building in workspace /mntf/jenkins/jobs/GerritBuilder/workspace
      Checkout:workspace / /mntf/jenkins/jobs/GerritBuilder/workspace - hudson.remoting.LocalChannel@72cbb9
      Using strategy: Gerrit Trigger
      Checkout:workspace / /mntf/jenkins/jobs/GerritBuilder/workspace - hudson.remoting.LocalChannel@72cbb9
      Fetching changes from 1 remote Git repository
      Fetching upstream changes from ssh://jenkins@localhost:29418/myrepo.git
      Commencing build of Revision 4514e900f88eb22c7c006aa8b8971f55e08b0324 ()
      FATAL: Null value not allowed as an environment variable: GIT_BRANCH
      java.lang.IllegalArgumentException: Null value not allowed as an environment variable: GIT_BRANCH
      at hudson.EnvVars.put(EnvVars.java:162)
      at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1101)
      at hudson.model.AbstractProject.checkout(AbstractProject.java:1195)
      at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:576)
      at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:465)
      at hudson.model.Run.run(Run.java:1409)
      at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:481)
      at hudson.model.ResourceController.execute(ResourceController.java:88)
      at hudson.model.Executor.run(Executor.java:238)

      The configuration of the trigger is along the lines given in Alex Blewitt's article (http://www.infoq.com/articles/Gerrit-jenkins-hudson). Specifically, the project and branch are configure as:

      Path - ** - Path - **

      Searching the forums, mailing lists, and irc logs did not yield a solution, so we're assuming it's a bug and not
      a config issue.

          [JENKINS-12921] Trigger fails to build with "Null value not allowed as an environment variable: GIT_BRANCH" error

          Ron K added a comment -

          There is also an exception visible in the Jenkins log, which might be related to this issue:

          Caused by: java.lang.AssertionError: class com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch is missing its descriptor in public java.util.List com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject.getBranches(). See https://wiki.jenkins-ci.org/display/JENKINS/My+class+is+missing+descriptor
          at hudson.model.Descriptor$PropertyType.getItemTypeDescriptorOrDie(Descriptor.java:194)

          The full stack trace of this exception can be seen here: http://pastebin.com/Nm5FVKZB

          Ron K added a comment - There is also an exception visible in the Jenkins log, which might be related to this issue: Caused by: java.lang.AssertionError: class com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch is missing its descriptor in public java.util.List com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject.getBranches(). See https://wiki.jenkins-ci.org/display/JENKINS/My+class+is+missing+descriptor at hudson.model.Descriptor$PropertyType.getItemTypeDescriptorOrDie(Descriptor.java:194) The full stack trace of this exception can be seen here: http://pastebin.com/Nm5FVKZB

          A workaround for this is to put $GERRIT_PATCHSET_REVISION as the branch specifier

          Garth Williamson added a comment - A workaround for this is to put $GERRIT_PATCHSET_REVISION as the branch specifier

          Ron K added a comment -

          Many thanks.

          Actually I had found another possible workaround - set the Checkout/merge to local branch (optional) field, located
          in one of the Advanced hideaways, to some arbitrary name. Then use the same name as the value of the branch specifier
          in Branches to build.

          Regarding the proposed workaround with $GERRIT_PATCHSET_REVISION - isn't it required to remove the newly-created branch
          (which will be named something like edb49a1f6...), otherwise it stays there, accumulates, and gets rebuilt every time? (saying
          that after looking at the Git Build Data->Built Branches information page)

          Ron K added a comment - Many thanks. Actually I had found another possible workaround - set the Checkout/merge to local branch (optional) field, located in one of the Advanced hideaways, to some arbitrary name. Then use the same name as the value of the branch specifier in Branches to build . Regarding the proposed workaround with $GERRIT_PATCHSET_REVISION - isn't it required to remove the newly-created branch (which will be named something like edb49a1f6... ), otherwise it stays there, accumulates, and gets rebuilt every time? (saying that after looking at the Git Build Data -> Built Branches information page)

          Sergey Mylnikov added a comment - - edited

          Have the same problem, when using more than one Git repo with "Gerrit Trigger" choosing strategy.
          Both workarounds not helping at all.

          FATAL: Null value not allowed as an environment variable: GIT_BRANCH
          java.lang.IllegalArgumentException: Null value not allowed as an environment variable: GIT_BRANCH
          at hudson.EnvVars.put(EnvVars.java:172)
          at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1123)
          at hudson.model.AbstractProject.checkout(AbstractProject.java:1369)
          at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:676)
          at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
          at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:581)
          at hudson.model.Run.execute(Run.java:1575)
          at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
          at hudson.model.ResourceController.execute(ResourceController.java:88)
          at hudson.model.Executor.run(Executor.java:241)

          git-plugin v1.4.0, git-client plugin v1.0.6, gerrit-trigger-plugin v2.10.1 (tested on old v2.5.3 - everything the same)

          Sergey Mylnikov added a comment - - edited Have the same problem, when using more than one Git repo with "Gerrit Trigger" choosing strategy. Both workarounds not helping at all. FATAL: Null value not allowed as an environment variable: GIT_BRANCH java.lang.IllegalArgumentException: Null value not allowed as an environment variable: GIT_BRANCH at hudson.EnvVars.put(EnvVars.java:172) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1123) at hudson.model.AbstractProject.checkout(AbstractProject.java:1369) at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:676) at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:581) at hudson.model.Run.execute(Run.java:1575) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:241) git-plugin v1.4.0, git-client plugin v1.0.6, gerrit-trigger-plugin v2.10.1 (tested on old v2.5.3 - everything the same)

          rsandell added a comment -

          It is the Git plugin that wants to add an env var to the build during checkout but fails

          at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1101)

          If you fill in a branch value in the git config section, you could put whatever you want here I think. I usually jut put in master, since the choosing strategy will check out a specific revision anyways.

          rsandell added a comment - It is the Git plugin that wants to add an env var to the build during checkout but fails at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1101) If you fill in a branch value in the git config section, you could put whatever you want here I think. I usually jut put in master, since the choosing strategy will check out a specific revision anyways.

          I think there is a bit misunderstanding... here what happens:

          First situation (WORKS FINE):
          ----------------------------------
          Repository URL: <url>
          Name: origin
          Refspec: $GERRIT_REFSPEC

          Branch Specifier (blank for default): master
          Choosing strategy: Gerrit Trigger
          ----------------------------------

          Second situation (FATAL: Null value not allowed as an environment variable: GIT_BRANCH):
          ----------------------------------
          Repository URL: <url>
          Name: origin
          Refspec: $GERRIT_REFSPEC

          Repository URL: <same url, or repo mirror url>
          Name: origin
          Refspec: $GERRIT_REFSPEC

          Branch Specifier (blank for default): master
          Choosing strategy: Gerrit Trigger
          ----------------------------------

          Third situation (WORKS FINE):
          ----------------------------------
          Repository URL: <url>
          Name: origin
          Refspec: $GERRIT_REFSPEC

          Repository URL: <same url, or repo mirror url>
          Name: origin
          Refspec: $GERRIT_REFSPEC

          Branch Specifier (blank for default): master
          Choosing strategy: default
          ----------------------------------

          Sergey Mylnikov added a comment - I think there is a bit misunderstanding... here what happens: First situation (WORKS FINE): ---------------------------------- Repository URL: <url> Name: origin Refspec: $GERRIT_REFSPEC Branch Specifier (blank for default): master Choosing strategy: Gerrit Trigger ---------------------------------- Second situation (FATAL: Null value not allowed as an environment variable: GIT_BRANCH): ---------------------------------- Repository URL: <url> Name: origin Refspec: $GERRIT_REFSPEC Repository URL: <same url, or repo mirror url> Name: origin Refspec: $GERRIT_REFSPEC Branch Specifier (blank for default): master Choosing strategy: Gerrit Trigger ---------------------------------- Third situation (WORKS FINE): ---------------------------------- Repository URL: <url> Name: origin Refspec: $GERRIT_REFSPEC Repository URL: <same url, or repo mirror url> Name: origin Refspec: $GERRIT_REFSPEC Branch Specifier (blank for default): master Choosing strategy: default ----------------------------------

          So... any thoughts why this happens?
          I really need to use two git repos with Gerrit Trigger choosing strategy, and I just can't do it. Workarounds not working for me.

          Sergey Mylnikov added a comment - So... any thoughts why this happens? I really need to use two git repos with Gerrit Trigger choosing strategy, and I just can't do it. Workarounds not working for me.

          As to why this happens, rsandell's explanation sounds quite convincing to me. However, for me the fix was to use $GERRIT_BRANCH (not $GERRIT_PATCHSET_REVISION) as the branch specifier. That's also what's recommended at [1]: "You may also need to set 'Branches to build' to $GERRIT_BRANCH".

          [1] https://wiki.jenkins-ci.org/display/JENKINS/Gerrit+Trigger#GerritTrigger-UsagewiththeGitPlugin

          Sebastian Schuberth added a comment - As to why this happens, rsandell's explanation sounds quite convincing to me. However, for me the fix was to use $GERRIT_BRANCH (not $GERRIT_PATCHSET_REVISION) as the branch specifier. That's also what's recommended at [1] : "You may also need to set 'Branches to build' to $GERRIT_BRANCH". [1] https://wiki.jenkins-ci.org/display/JENKINS/Gerrit+Trigger#GerritTrigger-UsagewiththeGitPlugin

          This issue still exists in the latest Jenkins version. I found a newer yet less voted bug with "kind of" workaround by Tsvi Mostovicz: https://issues.jenkins-ci.org/browse/JENKINS-38608?focusedCommentId=328089&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-328089

          I can confirm that this issue appears when I added new 4 string parameters to the task. The last parameter was a label parameter.

          Mikhail Tymchuk added a comment - This issue still exists in the latest Jenkins version. I found a newer yet less voted bug with "kind of" workaround by  Tsvi Mostovicz:   https://issues.jenkins-ci.org/browse/JENKINS-38608?focusedCommentId=328089&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-328089 I can confirm that this issue appears when I added new 4 string parameters to the task. The last parameter was a label parameter.

            Unassigned Unassigned
            ronk Ron K
            Votes:
            7 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated: