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

Windows Power Shell - Trying to execute SQL server Query using Windows Power shell Plugin and its throwing error as

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Blocker Blocker
    • powershell-plugin
    • None

      This has been assigned a sblocker because we have jenkins POC at ORG Level on wednesday and need to sort out before that

      Trying to execute SQL query using windows power shell plugin which is working fine in cmd but when i paste the same in Jenkin Windows power shell plugin its displaying below eeror

      SQLCMD -S DBINSTANCE -Q "Select Count from DBTABLE with (nolock);"

      Started by user anonymous
      Building in workspace C:\Program Files (x86)\Jenkins\jobs\WindowsPowerShell\workspace
      [workspace] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\WINDOWS\TEMP\hudson4262101233229977039.ps1'"
      The term 'SQLCMD' is not recognized as the name of a cmdlet, function, script f
      ile, or operable program. Check the spelling of the name, or if a path was incl
      uded, verify that the path is correct and try again.
      At C:\WINDOWS\TEMP\hudson4262101233229977039.ps1:1 char:7
      + SQLCMD <<<< -S DBINSTANCE -Q "Select Count from DBTABLE with (nolock);"
      + CategoryInfo : ObjectNotFound: (SQLCMD:String) [], CommandNotFo
      undException
      + FullyQualifiedErrorId : CommandNotFoundException

          [JENKINS-36689] Windows Power Shell - Trying to execute SQL server Query using Windows Power shell Plugin and its throwing error as

          Vamsi Kalyan added a comment -

          But if i execute same in windows powershell command prompt its working fine

          Vamsi Kalyan added a comment - But if i execute same in windows powershell command prompt its working fine

          Vamsi Kalyan added a comment -

          Can you please assign it to respective user as this is unassigned from yesterday

          Vamsi Kalyan added a comment - Can you please assign it to respective user as this is unassigned from yesterday

          Cody Konior added a comment -

          Jenkins runs PowerShell scripts under the service account of whatever the Jenkins/slave service is running under.

          This could potentially have a different PATH environment variable to the user you are using to confirm SQLCMD is available.

          Locate SQLCMD on your server and make sure the path is in the system PATH (which is valid for all users). It's unclear if you then need to restart the Jenkins instance but you could then try that. Failing all of this, specify the complete path in your script.

          (It's also best practice to prefix external commands in PowerShell with &).

          Cody Konior added a comment - Jenkins runs PowerShell scripts under the service account of whatever the Jenkins/slave service is running under. This could potentially have a different PATH environment variable to the user you are using to confirm SQLCMD is available. Locate SQLCMD on your server and make sure the path is in the system PATH (which is valid for all users). It's unclear if you then need to restart the Jenkins instance but you could then try that. Failing all of this, specify the complete path in your script. (It's also best practice to prefix external commands in PowerShell with &).

          Dirk Schiller added a comment - - edited

          Not sure if this helps. In my Case I had Issues with Invoke-SQL Cmdlet. I tried multiple things like Installing SQL Feature Packs 2008, 2012 and 2014 all in 64 Bit and also 32 Bit. But no luck with that. Then I created a new Jenkins Slave on a complete new Machine with the SQL Feature Pack 2012 64 Bit. And I installed firstly JRE 1.8 U121 32 Bit. But same Issues that Jenkins did not execute the Powershell which worked on the Comamndline without Errors. Then I uninstalled JRE 1.8 U121 32 Bit and installed JRE 1.8 U121 64 Bit and it still worked as expected without any Error. Seems that Jenkins uses the Powershell Architecture like the installed JRE Runtime. Means if you install JRE 32 Bit Jenkins will use a 32 Bit Powershell and if you isntall JRE 64 Bit Jenkins will use a 64 Bit Powershell. So if your Powershell works well on the Commandline / Powershell-Commandline but not in Jenkins then try to uninstall JRE 32 Bit and install JRE 64 Bit.

           

          Cheers

          Dirk

          Dirk Schiller added a comment - - edited Not sure if this helps. In my Case I had Issues with Invoke-SQL Cmdlet. I tried multiple things like Installing SQL Feature Packs 2008, 2012 and 2014 all in 64 Bit and also 32 Bit. But no luck with that. Then I created a new Jenkins Slave on a complete new Machine with the SQL Feature Pack 2012 64 Bit. And I installed firstly JRE 1.8 U121 32 Bit. But same Issues that Jenkins did not execute the Powershell which worked on the Comamndline without Errors. Then I uninstalled JRE 1.8 U121 32 Bit and installed JRE 1.8 U121 64 Bit and it still worked as expected without any Error. Seems that Jenkins uses the Powershell Architecture like the installed JRE Runtime. Means if you install JRE 32 Bit Jenkins will use a 32 Bit Powershell and if you isntall JRE 64 Bit Jenkins will use a 64 Bit Powershell. So if your Powershell works well on the Commandline / Powershell-Commandline but not in Jenkins then try to uninstall JRE 32 Bit and install JRE 64 Bit.   Cheers Dirk

            froque Filipe Roque
            vmaradana Vamsi Kalyan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: