12

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

Mani
  • 721
  • 3
  • 10
  • 24
  • Please [don’t post images of code, error messages, or other textual data.](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors) – tripleee Feb 08 '22 at 09:43

4 Answers4

10

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.

nichoio
  • 6,289
  • 4
  • 26
  • 33
3

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

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

manuelbcd
  • 3,106
  • 1
  • 26
  • 39
2

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

Frak
  • 832
  • 1
  • 11
  • 32
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