7

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!

Randy
  • 9,419
  • 5
  • 39
  • 56
  • 2
    Can you show the contents of that script? – Etan Reisner Nov 19 '15 at 15:05
  • 3
    The script creates `job.log` in the current directory. If you `cd` first then your current directory is wherever you `cd`ed to. If you don't it is wherever you are by default. So you are probably just not looking for the file in the right place. Use a full path for the output. – Etan Reisner Nov 19 '15 at 15:56
  • So that was the issue? You just weren't looking for the file in the correct directory? – Etan Reisner May 20 '16 at 01:53

1 Answers1

5

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.

Community
  • 1
  • 1
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148