0

I'm trying to run a very simple sh file that I added to my project, as part of my Jenkins build. I'm developing on Windows if it matters, and whenever the build comes to the line that runs the sh files I keep gettings Permissions denied.

Why does it happen?

ChikChak
  • 936
  • 19
  • 44

1 Answers1

2

Check the permissions on the sh file - it needs to be executable by the user that runs your Jenkins build.

Unfortunately I'm not very familiar with Windows, but I know that recent versions include a Linux shell so here is how to do it on Linux:

ls -l /path/to/example.sh

will show you something like this:

-rwxr-xr-x 1 myuser my group         519 Mar  7 14:54 example.sh

the first column in the output is the file permissions, and you're looking for an 'x' in at least the first position, which means it's executable by the owner (the value in the third column).

If you need to make the file executable, run

chmod +x /path/to/example.sh

which will make it executable by any user. This isn't always a good idea but the full subject of file permissions is a bit much to go into here; here's a good reference if you want to learn more.

gareth_bowles
  • 20,760
  • 5
  • 52
  • 82
  • But as I said I wrote it on Windows. So how can I do that? – ChikChak Jul 27 '19 at 18:17
  • 1
    @ChikChak before executing the sh script add a command to change the sh file permission. `chmod +x example.sh` – Chathuranga Abeyrathna Jul 28 '19 at 11:27
  • @ChikChak, [How to create file execute mode permissions in Git on Windows?](https://stackoverflow.com/questions/21691202/how-to-create-file-execute-mode-permissions-in-git-on-windows), or make your execute shell in-line (dot invocation) `. example.sh` – Ian W Jul 29 '19 at 06:52
  • @gareth-bowles, tho marked as accepted, perhaps you can extend your answer to include 'how to check/set'? – Ian W Jul 29 '19 at 07:43