randy randy - 6 months ago 245
Bash Question

gitlab-ci.yml not executing shell script

I set up gitlab-ci for my project, and inserted the following yml script:

---
buildJob:
only:
- master
script:
- "sh /var/www/gitTestFolder/scripts/build.sh"
stage: build
tags:
- ipsenh
deployJob:
only:
- master
script:
- "sh /var/www/gitTestFolder/scripts/deploy.sh"
stage: deploy
tags:
- ipsenh
testJob:
only:
- master
script:
- "sh /var/www/gitTestFolder/scripts/test.sh"
stage: test
tags:
- ipsenh
stages:
- build
- test
- deploy


This script runs in my gitlab server and shows the terminal that should execute the scripts
(/var/www..../script.sh)
.

The following result is for one of my jobs:

gitlab-ci-multi-runner 0.6.2 (3227f0a)
Using Shell executor...
Running on ipsenh...

Cloning repository...
Cloning into 'builds/05d0538a/0/root/ipsenh'...
Checking out 4288f64a as master...

$ sh /var/www/gitTestFolder/scripts/deploy.sh

Build succeeded.


The script however, never gets executed. If I execute this script locally on my server, it creates a file with simple text output. It never creates the file through this job however.


  • Script contents:

    echo "job executed" >> job.log



Do I have the wrong setup? Obviously its not the syntax and the permissions are allright, otherwise i'd get an error.

What could this be? Thx!

Answer

The current directory of a script is the directory the shell is in when the script is run, not the directory the script lives in.

So echo "job executed" >> job.log will create a job.log file in the current directory of the shell session and not in the directory with the script file.

If you want to use local paths to mean the script file's directory then you want to look at this answer and Bash FAQ 028.