Something I encounter every now and then on application deployments. This is common especially on the first time you commit/push your code to your Git repository with CI/CD configured.
Might have labeled or titled this article wrongly. The error does not happen when the app container is being created on OpenShift. It does not even reach that part during the build process.
Instead this happens at the 1st step, when the app is being built/compiled. So the pipeline will fail right away. But what I meant is that the process won’t be able to deploy to OpenShift since the build gets stopped.
Error message looks something like:
./gradlew: Permission denied
The Build stage will fail at this point because gradlew gets a permission denied error and therefore cannot execute the tasks that it is supposed to do.
It is easy to fix this issue with but a few Linux terminal commands.
Why does this happen?
The gradle wrapper build script – gradlew – needs to have its executable bit set on it. In Linux speak it means you are allowing the said script to be able to run as an executable on the system. It may be executable on your local development environment, but when sending code to the repository that executable bit does not get carried over.
In order to get that one bit set on the file, you would need the chmod command.
For this scenario, it is as simple as:
:-$ chmod +x gradlew
Now, this works only if you are also getting the same error when running the gradlew script locally. However, trying to git add and git commit the said file because it was “modified” will also not work. I mean, Git won’t see that change you just made to the file using the above command.
In order to fix this you will need another git command.
:-$ git update-index --chmod=+x gradlew
You are telling git that you are making this file an executable and to register it as a change. Or simply put, it updates or modifies the index of that working tree you are in (the branch) for the changes done to the target file.
Once you have entered the above command, you do not need to add the file to the index. You’ve already done that. Follow through with a commit instead. Then push your changes to the git repository and make the error go away.
Now your pipeline will get past the build stage successfully, then have that application running on Red Hat OpenShift like a boss. (Assuming no other logical code errors and JUnit issues happen, but that’s another topic of course!)
- I’m using GitLab for my projects
- This commonly happens on the 1st push to the remote repository
- The error is on the build process, not when the pod/container is being created on OpenShift
- > Using OpenShift Secrets With Spring Boot + Kafka October 2, 2020
- > SUSE Kickoff Menu October 31, 2006
- > Error: uncaught exception: Permission denied to call method XMLHttpRequest.open February 7, 2007
- > “PROGRAM_NAME” Is Not Recognized As An Internal Or External Command, Operable Program Or Batch File December 20, 2013
- > Creating Links Using Spring Boot HATEOAS June 6, 2020