JavaLover
JavaLover

Reputation: 73

User Permission in Jenkins

Inside Jenkins Jobs & Builds folder, I am creating a text file and writing some content through Java program. As I am part of corporate network, I am inside firewall with many security rules where I have been restricted to write/update the program files directory under C: drive. Although I am administrator in my local machine, however the company policies are still applied which is denying me access to write/delete any files from the Jenkins directory. I see Jenkins is nicely reading/modifying/writing any files/folders without any issues which is believed to the typical behavior of Jenkins's USER.

Question 1: Is there any way I can use this Jenkins's user through my code so I can avail access on to these directories?

Question 2: Are there ways to solve this issue through Java code? (Note: I have tried writing a file with Run as Administration java code as well)

Kindly let me know if I am missing any details,.any help is highly appreciated.

Upvotes: 0

Views: 2282

Answers (2)

Giri
Giri

Reputation: 411

It's about the user who launched the jenkins server, who might have the permissions to access the directories.

You can use the same user for your operations if available.

Question 1: Is there any way I can use this Jenkins's user through my code so I can avail access on to these directories? Jenkins users - Jenkins server can have its own users and privileges can be set for each users differently. You cannot use these users outside of Jenkins server. You can use the user who launched the Jenkins server, must be a user at OS level.

Question 2: Are there ways to solve this issue through Java code? (Note: I have tried writing a file with Run as Administration java code as well) Again, only OS level users can be used and not the Jenkins users(users created inside Jenkins server)

Upvotes: 1

Slav
Slav

Reputation: 27485

If you want your application to run with same credentials as Jenkins user, then hold Shift+Right Click your application, select "Run as different user", provide Jenkins's user credentials and press OK.

If you are launching your Java application from command line, do the Shift+Right Click on the cmd.exe first, and once again select "Run as different user"

If you want to impersonate a Windows user from within code, then you should really reword your question body and title (and remove Jenkins references as it has nothing to do with this). But even in this case, you need to know the credentials of the user you are trying to impersonate

Upvotes: 1

Related Questions