Access is denied prompted while windows sc command calling from jenkins groovy

12 views
Skip to first unread message

Mohit Mehral

unread,
Aug 13, 2019, 9:15:01 AM8/13/19
to Jenkins Users

I am trying to create CI/CD pipeline using jenkins and my environment devops/deployment is windows servers 2016. Pipeline script written in apache groovy. Which call batch file for deploy the code, that batch script is doing 2 tasks.

  • deploy code on another host machine (using robocopy command)
  • start w3svc service (using sc command).

Both command are mentioned in batch file which is call through groovy script with simple 'bat batchfilelocation /name.bat'. here is batch script:

@echo [off]
net use "\\<servername>\<shareddirectory>" <password> /user:<domain\user> /persistent:no
robocopy "C:\jenkins\AngularPipeline\dist\<project>" \\$<Dir>eddistinationServer>\<shar /E /PURGE
sc \\$servername start w3svc
echo on
echo close batch script!

For sc command execuation it is giving below error:

C:\jenkins\AngularPipeline>sc \ start w3svc [SC] StartService: OpenService FAILED 5: Access is denied.

This script is working well while I directly called it through command prompt(non administrator). access denied only comes while this script run under the jenkins groovy.

I have checked below possibilities :

  1. WMI permission on source and target machine
  2. //Confirm that WinRM is properly configured. c:>Winrm quickconfig
  3. //Make sure that the remote server allows commands from any machine. PS c:>Set-item wsman:localhost\client\trustedhosts -value *
  4. Restart Windows Remote management service restarted on both machines
  5. C:\Windows\system32>sc \ sdshow w3svc

D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)

Please suggest how to resolve the same.


I have noticed all batchfiles / powershell are running locally through command prompt however it not running through apache groovy. Is there any window setting I need to allow or jenkins parameter required to set for this.


Please help if you already phase similar issue.


Thanks

Mohit M

Slide

unread,
Aug 13, 2019, 10:35:54 AM8/13/19
to Jenkins User Mailing List
The user that Jenkins is running under probably doesn't have the necessary permissions. Check which user the service is running as and make sure that user has the necessary permissions. 

Not sure what you mean by the second part about PowerShell/batch files running under groovy. If you have a pipeline job, then it's using groovy. The implementation in the backend will launch PowerShell or cmd.exe to run the commands.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b54ecbc1-4b27-4675-b18b-3c5593405264%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages