Fetching a file in a shell script within a concourse task gives file not found error

253 Views Asked by At

My concourse task is something like this:

name: test
plan:
  - get: my-repo
  - task: my-task
    config:
      inputs:
      - name: my-repo  
      run:
        path: sh
        args: [my-repo/examples/run-this.sh]

And the shell script tries to fetch a file in so manner:

CONFIG_FILE=./$name.cfg

When I run the task, concourse throws this error

my-repo/examples/run-this.sh: line xx: can't open name.cfg: no such file

The location of the run-this.sh and name.cfg file are the same. Any pointers will be appreciated!

1

There are 1 best solutions below

0
On

Even though the two files share the same directory, the dot in ./name.cfg uses current working directory as a reference point - so it's the directory from which the script is called, not the directory in which the script is stored.

The best option to get this to work seems to be to add some intelligence to run-this.sh to locate the name.cfg file based on its own relative location, like this:

#!/bin/bash

SCRIPT_DIR="$(dirname $0)"
CONFIG_FILE="${SCRIPT_DIR}/name.cfg"

(...)