Permission denied error when executing shell script via GitLab CI/CD

Viewed 35

I have not used Linux or Gitlab much so this could be a newbie question. ( I have searched online for the same issue) In a gitlab pipeline I just want to execute a shell script. The runner is linux based runner using "docker+machine" executor. I am getting Permission denied when try to execute the script

GitLab Pipeline

init-job:
  image: "docker.mycompany/templates/terraform"
  stage: build
  script:
    - ls
    - whoami
    - uname -r
    - ./mydeploy.sh

runner output

enter image description here

mydeploy.sh

#!/bin/bash
echo "this is from shell script"

UPDATE 1
after changing the pipeline job to use chmod +x mydeploy.sh It does not throw error, however it does not execute the script as well. The echo in the .sh script should output the text.

enter image description here

1 Answers

Just use

git update-index --chmod=+x mydeploy.sh
git ls-files --stage # you can check permissons
git commit -m "Executable!"

docs for git update-index

Related