'Gitlab Shell Script Permission Denied

I am running a simple shell script with Gitlab CICD and I am getting Permission denied. Kindly suggest

When I do chmod +x test.sh it says operation not permitted.

stages:
  - build 

build: 
  stage: build 
  script: 
    - ls
    - ./test.sh

Shell test.sh

echo Hi

Error:

enter image description here



Solution 1:[1]

You have to either:

1- Run bash ./test.sh

OR

2- Add the line #!/bin/bash to the top of test.sh so that it knows to run it within bash

Solution 2:[2]

The line 23 tells that it is trying to execute the script with /bin/bash, but it doesn't have the permissions.

Try to give execution permision to the file by running this command:

sudo chmod 755 test.sh

Solution 3:[3]

bash /the-script.sh is the best solution afaik

https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2672

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 frakman1
Solution 2 Fernando Rodriguez
Solution 3 manuelbcd