Gitlab Shell Script Permission Denied

Viewed 5124

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

4 Answers

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

Instead of simply running chmod on your local system, it's better to run git update-index --chmod=+x path/to/file. This adds an executable flag to a file in Git and should ensure that a script can be executed inside a GitLab pipeline.

See also this question.

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
Related