I’m having trouble running a Jenkins script.
When the following script is run from the location (PS)
C:\jenkins\script.ps1
the final result of the script dumps to a file
C:\jenkins\sendsms_blocker24h.txt
in format
Role;Server;Level;Message;Sender;Description;
SMS;Win1;0;Blocker: testuser;SMS;Information about blocked domain users;
When I add in jenkins to start and run ‘Build now’ a file is created
C:\jenkins\sendsms_blocker24h.txt
Hi @marbda. Your script has an if/else block in it; if the else block is triggered (i.e., $blocked_users is false-y), then your file will be empty. Perhaps the Jenkins user doesn’t have the proper permissions in order to read the AD users?
So that lends credence to my theory above: Jenkins can write to the path C:\Jenkins, but cannot execute Get-ADUser -Filter * -Properties * or is getting an incomplete list of users. Your script then tests if there were any blocked users, and seeing that there were none, wrote an empty string out to the sendsms_blocker24h.txt file. I’d dig deeper into those permissions and see if Jenkins can execute Get-ADUser successfully.
I would recommend adding logging into your script. Dump objects at various stages and verify things are working as expected. Another thing to look at is the environment variables that may be present when you run the script vs. when Jenkins runs the script.