Setting up Gradle CI build for Github Actions with the build action for Gradle https://github.com/gradle/gradle-build-action is straight forward after you have either initialize your Eclipse project with Gradle or added Gradle build support afterwards. This project is a Xtext project, but for the continuous integration (CI) it doesn’t matter since we are using Gradle build automation tool. Here’s the ci yaml file which is close to the template given.
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build
But we are hitting an error when trying to execute the Github Action pipeline. Error Gradle script /home/runner/work/*/gradlew is not executable.
This is a permission issue. To fix it we need to give it permission to execute the file by changing the file’s properties.
Solution 1 (preferred gradle setup)
In VS code or command prompt run chmod command
git update-index --chmod=+x gradlew
Then check the changes in your source control and run your Github Action pipeline again.
Solution 2 (Alternative)
If you’re not able to change it for the source control for whatever reason, you can do it directly in the pipeline by adding an addition step
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
Solution 3 (execution permission)
This is similar to solution 2 but can help troubleshoot locally.
This error typically occurs when trying to execute a Gradle script that does not have executable permissions. To fix this, you can give the script executable permissions by running the following command in your terminal:
chmod +x /path/to/gradlew
Replace /path/to/gradlew
with the actual path to your gradlew
file. This command will give the gradlew
file executable permissions, which should allow you to run it without encountering the error.
If you’re using a Windows machine, you can try running the command:
.\gradlew.bat
This should execute the Gradle script without needing to give it executable permissions.