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

Environment variable too long error when building .NET Core project

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None

      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.

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

              Created:
              Updated: