I'm getting this console output when running a Jenkins job on a slave. The job should create a file and put it in
Get-Service | Export-CSV c:\foo\service.csv
[AnonymousJWTApi] $ powershell.exe -NonInteractive -ExecutionPolicy
Started by user anonymous
Building remotely on slave1 in workspace C:\Jenkins\Master\workspace\AnonymousJWTApi
> git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git.exe config remote.origin.url C:\Users\xxx\Source\Repos\AnonymousJWTApi # timeout=10
Fetching upstream changes from C:\Users\xxx\Source\Repos\AnonymousJWTApi
> git.exe --version # timeout=10
> git.exe -c core.askpass=true fetch --tags --progress C:\Users\xxx\Source\Repos\AnonymousJWTApi +refs/heads/*:refs/remotes/origin/*
Seen branch in repository origin/master
Seen 1 remote branch
Checking out Revision a7087f81af855cc96b8763a5ec66b96c19a44a30 (origin/master)
> git.exe config core.sparsecheckout # timeout=10
> git.exe checkout -f a7087f81af855cc96b8763a5ec66b96c19a44a30
> git.exe rev-list a7087f81af855cc96b8763a5ec66b96c19a44a30 # timeout=10
[AnonymousJWTApi] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\xxx\AppData\Local\Temp\hudson1582303083838020200.ps1'"
-ExecutionPolicy Bypass ensures that the script file can be run regardless of the execution policy in place for the computer or user. It is correct, and it is not the cause of your issue.
The problem may be permissions.
The Jenkins slave agent is running as a certain user; either the user you used to start it, or if it's running as a service, then it will be the service account.
The user may not have permission to write to
C:\Foo, so you can check that.
Another way to test this is to write to the workspace directory, so do something like this:
Get-Service | Export-CSV $env:WORKSPACE\service.csv
That should work. If it does, then change the permission on the
C:\Foo directory, or run the slave as an account that already has permission.
Here's a way you might be able to tell both which user is running the service, and where the workspace directory is:
Get-ChildItem env:\ | Out-String | Set-Content -Path $env:USERPROFILE\env.txt
This will write a file called
env.txt to the profile of the user running the script, containing all of the environment variables (including
%WORKSPACE%). You'll just have to browse through each user profile to see where it ends up, and then you'll also know the user.