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

Environment variable too long error when building .NET Core project

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None

    Description

      I cannot build a windows service .NET Classic (v4.6.1) project that references ASP.NET Core libraries (for REST API functionality)

      Pipeline code:

      bat "\"${tool 'MSBuild 2017'}\" /p:Configuration=Release /p:Platform=\"${targetPlatform}\" /p:TargetFrameworkVersion=${dotnetVersion} /p:OutputPath=\"${WORKSPACE}\\${buildOutputPath}\""
      
      

      Jenkins runs this command

      "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe" /p:Configuration=Release /p:Platform="x86" /p:TargetFrameworkVersion=v4.6.1 /p:OutputPath="E:\Jenkins\workspace\repo_name_branch\output"
      

      I get the following error:

      [2019-05-13T14:43:55.488Z] Done executing task "MSBuild". (TaskId:228)
      [2019-05-13T14:43:55.488Z] Done building target "Build" in project "Service.sln".: (TargetId:5)
      [2019-05-13T14:43:55.488Z] Done Building Project "E:\Jenkins\workspace\repo_name_branch\Service.sln" (default targets).
      [2019-05-13T14:43:55.488Z] 
      [2019-05-13T14:43:55.488Z] Unhandled Exception: Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Environment variable name or value is too long.
      [2019-05-13T14:43:55.488Z] =============
      [2019-05-13T14:43:55.488Z] System.ArgumentException: Environment variable name or value is too long.
      [2019-05-13T14:43:55.488Z]    at System.Environment.SetEnvironmentVariable(String variable, String value)
      [2019-05-13T14:43:55.488Z]    at Microsoft.Build.BackEnd.InProcNode.HandleShutdown(Exception& exception)
      [2019-05-13T14:43:55.488Z]    at Microsoft.Build.BackEnd.InProcNode.Run(Exception& shutdownException)
      [2019-05-13T14:43:55.488Z] 
      [2019-05-13T14:43:55.488Z]  ---> System.ArgumentException: Environment variable name or value is too long.
      [2019-05-13T14:43:55.488Z]    at System.Environment.SetEnvironmentVariable(String variable, String value)
      [2019-05-13T14:43:55.488Z]    at Microsoft.Build.BackEnd.InProcNode.HandleShutdown(Exception& exception)
      [2019-05-13T14:43:55.488Z]    at Microsoft.Build.BackEnd.InProcNode.Run(Exception& shutdownException)
      [2019-05-13T14:43:55.488Z]    --- End of inner exception stack trace ---
      [2019-05-13T14:43:55.488Z]    at Microsoft.Build.Shared.ErrorUtilities.ThrowInternalError(String message, Exception innerException, Object[] args)
      [2019-05-13T14:43:55.488Z]    at Microsoft.Build.BackEnd.InProcNode.Run(Exception& shutdownException)
      [2019-05-13T14:43:55.488Z]    at Microsoft.Build.BackEnd.NodeProviderInProc.InProcNodeThreadProc()
      [2019-05-13T14:43:55.488Z]    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
      [2019-05-13T14:43:55.488Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
      [2019-05-13T14:43:55.488Z]    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
      [2019-05-13T14:43:55.488Z]    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      [2019-05-13T14:43:55.488Z]    at System.Threading.ThreadHelper.ThreadStart()
      script returned exit code -532462766

      So I get an Environment variable name or value is too long. error from MsBuild.

      The funny thing is, that running the same command in cmd terminal on the very same computer works. Only under Jenkins seems the build not working. I tried to run Jenkins as a windows service (under SYSTEM user), or just as a regular process under my own user account. Both times this fails for the same reason.

      Attachments

        Activity

          elektromodulator Péter Kovács added a comment - - edited

          I also tried using powershell step instead of bat step, but the same error occures.

          elektromodulator Péter Kovács added a comment - - edited I also tried using powershell step instead of bat step, but the same error occures.
          jameswithers James Withers added a comment -

          I had this issue whilst using MSBuild and MSDeploy, was a very long build parameter that was being added to the env variables.

          I found this using the verbose flag and was able to null the env variable by parsing the info I needed out of it and then disposing of it by setting it to an empty string.

          jameswithers James Withers added a comment - I had this issue whilst using MSBuild and MSDeploy, was a very long build parameter that was being added to the env variables. I found this using the verbose flag and was able to null the env variable by parsing the info I needed out of it and then disposing of it by setting it to an empty string.
          danielwu Daniel Wu added a comment -

          runnging the following cmd via jenkins gives me the exactly error, but the same command works on this machine, I have tested, I also tried devenv to build the solution, nothing changes
          C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" Server/Project.sln -restore /p:Configuration="Release" /p:Platform="Any CPU"

          danielwu Daniel Wu added a comment - runnging the following cmd via jenkins gives me the exactly error, but the same command works on this machine, I have tested, I also tried devenv to build the solution, nothing changes C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" Server/Project.sln -restore /p:Configuration="Release" /p:Platform="Any CPU"

          People

            kohsuke Kohsuke Kawaguchi
            elektromodulator Péter Kovács
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: