-1

I have tried to execute below commands from Jenkins consecutively:

Import-Module -Name "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"
cd IPL:

But it seems like Jenkins is releasing the session after executing each command. Hence we have tried to keep a delay between two command, but no luck:

Import-Module -Name "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"
Start-Sleep -s 5
cd IPL:

While executing script, Jenkins is taking each command from its workspace directory D:\jenkins\workspace\<JobName>. I was looking to modify the configuration in such a way, where Jenkins will execute entire script (with all commands within) from the same drive where script is located. Not from the Jenkins workspace.

But not such materials available in google. I have looked into the Jenkins Workspace modification area (Jenkins->Manage Jenkins->Configure System and click on the Advanced)

Jenkins Workspace Modification

But it will not help as, it will only change the workspace path and whenever we will execute the script. Again it will take individual command inside workspace and will execute them over there instead of directory where script is located.

Is there any way can we execute all the command (from a single powershell script) without terminate the session for each command? So that the powershell script script can be executed for it own directory only?

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
Krish
  • 1
  • 2
  • jenkins definitely doesn't close the PS session between PS commands – 4c74356b41 Feb 03 '17 at 13:20
  • The any idea, why after importing SCCM *.psd modules the cd : command is not working? – Krish Feb 03 '17 at 13:22
  • well, did you check that the import succeeds? can you at least see the commands in the session? – 4c74356b41 Feb 03 '17 at 13:23
  • Yea.. I have done [Import-Module -Name "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1" -verbose] VERBOSE. It is showing that all the modules get updated. But right after cd IPL: command got failed throwing error (Drive not found). While the same commands get executed in Windows PowerShell console and I cam get inside IPL CMDrive (which is virtual) – Krish Feb 03 '17 at 13:25
  • Yes Mike.. I have started the same discussion. Do you have any suggestion how to fix it? – Krish Feb 06 '17 at 05:05
  • It's duplicate of already deleted question, so it should be re-opened. – kenorb Feb 18 '18 at 22:29

2 Answers2

0

Anyway, to answer this question (not touching the SCCM part).

Jenkins will execute all the command that are in the SAME step during the same Powershell session, so if you have 1 step in your Jenkins job, all the commands you put in there will be executed in the same PS shell.

As for the second question, you can use Set-Location to change the current working directory of powershell.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • Actually, we were able to execute the multiple commands in PS session. The only the issue is after importing the module, the session is not accessible/active. When, we have execute these commands manually from Windows power shell, able to see the IPL CMdrive (Virtual). But when the same commands executed through windows PS on Jenkins, getting the mentioned error "IPL drive does not exists" – Krish Feb 06 '17 at 06:24
  • Error Message from Jenkins: Set-Location : Cannot find drive. A drive with the name 'IPL' does not exist. At C:\Windows\TEMP\hudson5556720245749845343.ps1:4 char:1 + Set-Location IPL: -verbose + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (IPL:String) [Set-Location], Dri veNotFoundException + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetL ocationCommand – Krish Feb 06 '17 at 07:06
  • well, this question is not about SCCM, rather about executing all the commands in one session, and that's the answer to that question @Krish – 4c74356b41 Feb 06 '17 at 21:45
  • Yea... Today I have found one fix.... – Krish Feb 07 '17 at 05:14
0

Windows Powershell was running using \Administrator account while Jenkins was running with System Account. So we have change the Jenkins service Logon from System account to Domain account: First, downloaded “PsExec.exe” and execute following command from command prompt ("C:\Users\Administrator.DUMMYIPSL\Desktop\PsExec.exe" –i –s cmd.exe) / Second, opened up Jenkins service and open the properties tab. Now from the Logon tab to change the priviliges from System account to the Domain Admin account and restarted the Jenkins service to execute the script. / Third, then triggered the build from Jenkins and it worked.

Krish
  • 1
  • 2