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

Errorlevel checking in windows .bat scripts returns false negatives

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

      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

            [BSERV-10020] Errorlevel checking in windows .bat scripts returns false negatives

            Dave Chevell made changes -
            Fix Version/s New: 5.4.0 [ 73619 ]
            Affects Version/s New: 5.3.7 [ 77792 ]
            Dave Chevell made changes -
            Resolution New: Fixed [ 1 ]
            Status Original: Gathering Impact [ 12072 ] New: Closed [ 6 ]
            Owen made changes -
            Workflow Original: Stash Workflow - Restricted [ 2419376 ] New: JAC Bug Workflow v3 [ 3136826 ]
            Status Original: Open [ 1 ] New: Gathering Impact [ 12072 ]
            Owen made changes -
            Symptom Severity Original: Minor [ 14432 ] New: Severity 3 - Minor [ 15832 ]
            Dave Chevell made changes -
            Assignee New: Dave Chevell [ dchevell ]
            Andrei Khudavets made changes -
            Status Original: Needs Triage [ 10030 ] New: Open [ 1 ]
            Andrei Khudavets made changes -
            Component/s New: Installer - Windows [ 28790 ]
            Dave Chevell made changes -
            Description Original: h3. 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.

            h3. Steps to Reproduce
            # Edit *set-bitbucket-home.bat* and comment out the value for {{BITBUCKET_HOME}}, eg.:
            {code:title=set-bitbucket-home.bat}
            rem set BITBUCKET_HOME=C:\\Atlassian\\ApplicationData\\Bitbucket
            {code}This will cause *set-bitbucket-home.bat* to return an error after it's called.
            # Run *<bitbucket-install>/bin/start-bitbucket.bat*


            h3. Expected Results
            When the following codepath runs in *start-bitbucket.bat*, it should exit immediately after *set-bitbucket-home.bat* returns errors:
            {code:title=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
            {code}

            h3. Actual Results
            *start-bitbucket.bat* _does not exit_ and continues running, until the underlying problem causes another error to occur: {code}
            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"
            {code}

            h3. Workaround
            Substitute {{if not errorlevel 0}} for {{if errorlevel 1}}, which returns true for *all error levels greater than or equal to 1*
            New: h3. 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.

            h3. Steps to Reproduce
            # Edit *set-bitbucket-home.bat* and comment out the value for {{BITBUCKET_HOME}}, eg.:
            {code:title=set-bitbucket-home.bat}
            rem set BITBUCKET_HOME=C:\\Atlassian\\ApplicationData\\Bitbucket
            {code}This will cause *set-bitbucket-home.bat* to return an error after it's called.
            # Run *<bitbucket-install>/bin/start-bitbucket.bat*


            h3. Expected Results
            When the following codepath runs in *start-bitbucket.bat*, it should exit immediately after *set-bitbucket-home.bat* returns errors:
            {code:title=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
            {code}In other words, the following error should be printed, and then the script should immediately exit without proceeding further:
            {code}
            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
            {code}

            h3. Actual Results
            *start-bitbucket.bat* _does not exit_ and continues running, until the underlying problem causes another error to occur: {code}
            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"
            {code}

            h3. Workaround
            Substitute {{if not errorlevel 0}} for {{if errorlevel 1}}, which returns true for *all error levels greater than or equal to 1*
            Dave Chevell made changes -
            Description New: h3. 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.

            h3. Steps to Reproduce
            # Edit *set-bitbucket-home.bat* and comment out the value for {{BITBUCKET_HOME}}, eg.:
            {code:title=set-bitbucket-home.bat}
            rem set BITBUCKET_HOME=C:\\Atlassian\\ApplicationData\\Bitbucket
            {code}This will cause *set-bitbucket-home.bat* to return an error after it's called.
            # Run *<bitbucket-install>/bin/start-bitbucket.bat*


            h3. Expected Results
            When the following codepath runs in *start-bitbucket.bat*, it should exit immediately after *set-bitbucket-home.bat* returns errors:
            {code:title=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
            {code}

            h3. Actual Results
            *start-bitbucket.bat* _does not exit_ and continues running, until the underlying problem causes another error to occur: {code}
            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"
            {code}

            h3. Workaround
            Substitute {{if not errorlevel 0}} for {{if errorlevel 1}}, which returns true for *all error levels greater than or equal to 1*
            Dave Chevell created issue -

              dchevell Dave Chevell
              dchevell Dave Chevell
              Affected customers:
              0 This affects my team
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: