PSfan
PSfan

Reputation: 75

Powershell and Jenkins - Execute Powershell Script as another user

I have an environment formed by a Jenkins Server, a couple of Jenkins Slaves (windows) and several remote windows computers all part of the same domain.

I need to run a jenkins job, which executes a powershell snippet consisted of several functions (part of a custom modules loaded on the Jenkins Slave) against other windows remote computers in the same domain (which do not have the modules installed).

These modules needs to run under a specific domain account with permissions to access the remote computers.

If I logon with on any of the jenkins slave (with that specific domain account) everything works fine.

By default, Jenkins executes the job on the slave using the NT authority\system account which, of course, returns me denied access errors.

Question: is there a way to tell Jenkins to execute the Job on the windows slave with another specific Domain Account and not the NT Authority\System one?

Tried already:

Upvotes: 4

Views: 3395

Answers (1)

Ranadip Dutta
Ranadip Dutta

Reputation: 9133

You can run powershell as a process in a script and call that from Jenkins. In the script also you can use like:

$username = 'username'
$password = 'password'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username,$securePassword

Start-Process Powershell.exe -Credential $credential

Hope it helps.

Upvotes: 2

Related Questions