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

Problem using MSBuild Tool name in multi-line batch file in Pipeline script

       
      In Jenkins->Global Tool Configuration->MSBUILD

      I Added a MSBUILD like below

      Name: MSBuildTool2017

      Path to MSBuild: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe

      Variable ${tool 'MSBuildTool2017'} can be recognized in one-line batch script but not in the multi-line script, Why?

      Is there any way I can void the hardcoded MSBUILd Tool Path in the batch script of Jenkins pipeline script?

      def buildSource() { //${tool 'MSBuildTool2017'} is recognized.
       bat "\"${tool 'MSBuildTool2017'}\" ABC.sln /p:Configuration=Release /p:Platform=\"x64\" /t:rebuild"
      }

      def BuildABC() { //${tool 'MSBuildTool2017'} is not recognized.
       {

      bat label: '', script: '''@echo off

      set RETVAL=0

      echo Navigating to ABC folder
      cd %WORKSPACE%
      cd project

      echo Cleaning up bin folder
      REM del bin_x64
      *.exe /F /Q /S
      REM if NOT "%errorlevel%" == "0" set RETVAL=%errorlevel%

      echo Navigating to InstallActionsolution folder
      cd ABC

      echo Building ABC Binaries
      \"${tool 'MSBuildTool2017'}\" "ABC.sln" /p:Configuration=Release /p:Platform=\"x64\" /t:rebuild

      if NOT "%errorlevel%" == "0" set RETVAL=%errorlevel%

      exit %RETVAL%'''
      }

          [JENKINS-57596] Problem using MSBuild Tool name in multi-line batch file in Pipeline script

          Ming Liang created issue -
          Ming Liang made changes -
          Description Original:  
          In Jenkins->Global Tool Configuration->MSBUILD

          I Added a MSBUILD like below

          Name: MSBuildTool2017

          Path to MSBuild: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe

          Variable ${tool 'MSBuildTool2017'} can be recognized in one-line batch script but not in the multi-line script, Why?

          Is there any way I can void the hardcoded MSBUILd Tool Path in the batch script of Jenkins pipeline script?

          def buildSource() \{ //${tool 'MSBuildTool2017'} is recognized.
           {{bat "\"${tool 'MSBuildTool2017'}\" ABC.sln /p:Configuration=Release /p:Platform=\"x64\" /t:rebuild"}}
          }

          def BuildABC() \{ //${tool 'MSBuildTool2017'} is not recognized.
           {{bat label: '', script: '''@echo off

          set RETVAL=0

          echo Navigating to ABC folder
          cd %WORKSPACE%
          cd project

          echo Cleaning up bin folder
          REM del bin_x64\\*.exe /F /Q /S
          REM if NOT "%errorlevel%" == "0" set RETVAL=%errorlevel%

          echo Navigating to InstallActionsolution folder
          cd ABC

          echo Building ABC Binaries
          \"${tool 'MSBuildTool2017'}\" "ABC.sln" /p:Configuration=Release /p:Platform=\"x64\" /t:rebuild

          if NOT "%errorlevel%" == "0" set RETVAL=%errorlevel%

          exit %RETVAL%'''}}
          }
          New:  
           In Jenkins->Global Tool Configuration->MSBUILD

          I Added a MSBUILD like below

          Name: MSBuildTool2017

          Path to MSBuild: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe

          Variable ${tool 'MSBuildTool2017'} can be recognized in one-line batch script but not in the multi-line script, Why?

          Is there any way I can void the hardcoded MSBUILd Tool Path in the batch script of Jenkins pipeline script?

          def buildSource() \{ //${tool 'MSBuildTool2017'} is recognized.
            {{bat "\"${tool 'MSBuildTool2017'}\" ABC.sln /p:Configuration=Release /p:Platform=\"x64\" /t:rebuild"}}
           }

          def BuildABC() \{ //${tool 'MSBuildTool2017'} is not recognized.
            {

          bat label: '', script: '''@echo off

          set RETVAL=0

          echo Navigating to ABC folder
           cd %WORKSPACE%
           cd project

          echo Cleaning up bin folder
           REM del bin_x64
          *.exe /F /Q /S
           REM if NOT "%errorlevel%" == "0" set RETVAL=%errorlevel%

          echo Navigating to InstallActionsolution folder
           cd ABC

          echo Building ABC Binaries
           \"${tool 'MSBuildTool2017'}\" "ABC.sln" /p:Configuration=Release /p:Platform=\"x64\" /t:rebuild

          if NOT "%errorlevel%" == "0" set RETVAL=%errorlevel%

          exit %RETVAL%'''
           }
          Ming Liang made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]

          Ming Liang added a comment -

           

          bat label: '', script: '''@echo off

          changed to

           

          bat label: '', script: """@echo off{{}}

          Ming Liang added a comment -   bat label: '', script: '''@echo off changed to   bat label: '', script: """@echo off {{}}
          Ming Liang made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: In Progress [ 3 ] New: Resolved [ 5 ]

            marshall777 Lionel Cabasson
            liangming2003 Ming Liang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: