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!

3
  • 2
    Can you show the contents of that script? Commented Nov 19, 2015 at 15:05
  • 3
    The script creates job.log in the current directory. If you cd first then your current directory is wherever you cded 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. Commented Nov 19, 2015 at 15:56
  • So that was the issue? You just weren't looking for the file in the correct directory? Commented May 20, 2016 at 1:53

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.