Q&A: Accessing Files from Jenkins
Image from the LinkedIn Learning course "Setting up a desktop PC"

Q&A: Accessing Files from Jenkins

Question

Is there a way to make a Jenkins job run an .exe file that, for example, is on the desktop?

Short answer

Maybe. You can have Jenkins run an executable from almost any location on the system as long as the Jenkins process has permission to read and execute the file. If you're running an executable from your desktop, Jenkins will need to be running on the same system.

Long Answer

If you are running Jenkins on a Mac or Linux server, AND your desktop is on the same system, your personal user will have a desktop path something like "/Users/username/Desktop". If you're running Jenkins on a Windows server, AND your desktop is on the same system, your desktop path will look like "C:\Users\username\Desktop". In either case, that's the path you'll need to use in your Jenkins job.

With the path in place, you'll need to make sure Jenkins can access that location. This may be difficult as some systems may restrict permissions to files under "/Users" and "C:\Users" to the user that owns the "username" folder. One way to test this is to create a job that lists your Desktop from Jenkins. Use an "Execute Shell" build step on Mac/Linux and "Execute Windows batch command" on Windows. In either case, enter a command like "ls /Users/username/Desktop" (Mac/Linux) or "dir C:\Users\username" (Windows). If that test passes, Jenkins can see your Desktop. If not, and you really want the file to be run from there, you will need to modify permissions on your Desktop directory/folder and possibly the path leading up to it. That can be difficult and is almost always not the right choice because it can introduce insecurity to your system.

With that said, I would suggest (if at all possible) using a designated path on your system that you know Jenkins can read and run programs from. If you're running a build and that build places the executable on your desktop, see if you can configure the build to place the file in a directory/folder outside of your desktop, perhaps '/usr/local/bin' on Mac/Linux or something similar on Windows. Then configure your Jenkins job to run from there.

The option you probably want to use is a "File Parameter" to upload the executable directly to your job. This will be especially useful if Jenkins is not running on the system where your desktop is located. Jenkins will upload the file to a path relative to the job's workspace. In your job, you'll use the parameter variable to run the uploaded file. Access won't be a problem but on Mac/Linux systems you may need to make the file executable after uploading.

This build is parameterized -> File parameter

Be careful with how you handle uploaded files though; allowing users to upload and run executables on your Jenkins server may be insecure.

Faiz Ahmed

Airline Pricing | Airline Refunds | EMD | Observability | Quality | Security | Consulting

2y

Hi Michael, It was an informative read. I had a related query, if you could help. I am uploading an excel file, thru file parameter. These files are getting copied but are not opening and therefore are not accessible to another build step. The error shown is like file is corrupt or extension is wrong(Extension is actually correct). I suspect similar access related issues.

Like
Reply

To view or add a comment, sign in

More articles by Michael J.

Insights from the community

Others also viewed

Explore topics