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

Environment variable too long error when building .NET Core project

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Labels:
      None
    • Environment:
    • Similar Issues:

      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

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

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

          Show
          elektromodulator Péter Kovács added a comment - - edited I also tried using powershell step instead of bat step, but the same error occures.
          Hide
          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.

          Show
          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.

            People

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

              Dates

              Created:
              Updated: