Uploaded image for project: 'Bitbucket Data Center'
  1. Bitbucket Data Center
  2. BSERV-10020

Errorlevel checking in windows .bat scripts returns false negatives

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Low
    • 5.4.0
    • 5.3.7
    • Installer - Windows
    • None

    Description

      Summary

      Some of Bitbucket's .bat files use the following form to check for errors:
      if not errorlevel 0 …

      The problem is that Windows actually treats errorlevel comparison as a greater-than-or-equal-to operation. In other words, in the presence of errorlevel 1, the test if not errorlevel 0 … will actually return false instead of true.

      Steps to Reproduce

      1. Edit set-bitbucket-home.bat and comment out the value for BITBUCKET_HOME, eg.:
        set-bitbucket-home.bat
        rem set BITBUCKET_HOME=C:\\Atlassian\\ApplicationData\\Bitbucket
        

        This will cause set-bitbucket-home.bat to return an error after it's called.

      2. Run <bitbucket-install>/bin/start-bitbucket.bat

      Expected Results

      When the following codepath runs in start-bitbucket.bat, it should exit immediately after set-bitbucket-home.bat returns errors:

      start-bitbucket.bat
      call %BIN_DIR%\set-bitbucket-home.bat
      if not errorlevel 0 exit /b
      
      if "%1" == "/no-search" set NO_SEARCH=1
      
      echo Starting Atlassian Bitbucket
      

      In other words, the following error should be printed, and then the script should immediately exit without proceeding further:

      c:\Atlassian\Bitbucket\5.2.2\bin>start-bitbucket.bat
      Bitbucket doesn't know where to store its data. Configure the BITBUCKET_HOME
      environment variable with the directory where Bitbucket should store its data.
      Ensure the path to BITBUCKET_HOME does not contain spaces. BITBUCKET_HOME may
      be configured in set-bitbucket-home.bat, if preferred, rather than exporting it
      as an environment variable
      

      Actual Results

      start-bitbucket.bat does not exit and continues running, until the underlying problem causes another error to occur:

      c:\Atlassian\Bitbucket\5.2.2\bin>start-bitbucket.bat
      Bitbucket doesn't know where to store its data. Configure the BITBUCKET_HOME
      environment variable with the directory where Bitbucket should store its data.
      Ensure the path to BITBUCKET_HOME does not contain spaces. BITBUCKET_HOME may
      be configured in set-bitbucket-home.bat, if preferred, rather than exporting it
      as an environment variable
      Starting Atlassian Bitbucket
      "_start-search.bat is not intended to be run directly. Run start-bitbucket.bat instead"
      "_start-webapp.bat is not intended to be run directly. Run start-bitbucket.bat instead"
      "To start the Bitbucket webapp without starting search, run start-bitbucket.bat /no-search"
      

      Workaround

      Substitute if not errorlevel 0 for if errorlevel 1, which returns true for all error levels greater than or equal to 1

      Attachments

        Activity

          People

            dchevell Dave Chevell
            dchevell Dave Chevell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: