I have a job with a step to call a script
- run:
name: Install JS dependencies
command: <<include(scripts/install_js_dependencies.sh)>>
This works fine, I have this script in my scripts
folder
But the install_js_dependencies.sh
script has a call to another script common.sh
, which contains a bunch of functions that are reused in other scripts (sorry it’s probably getting convoluted!)
install_js_dependencies.sh
gets called, but it fails with an error that it can’t find common.sh
/bin/bash: line 7: common.sh: No such file or directory
common.sh
is also in my scripts folder.
I can not work out how to make one script call another; Is any one able to point me in the right direction please?
I would start by replacing the call to common.sh
with a ls -lah && pwd
. This feels to me an issue of relative file paths.
I have the same issue. The present working directory ends up being /bin, and helper scripts aren’t under that directory. Where are orb scripts extracted to?
Hello all,
This is a misunderstanding of how an orb is packed.
This will not work because you are not shipping the scripts with your orb, it is just a convenience for writing the orb.
When you run the circleci orb pack
command, this code:
- run:
name: Install JS dependencies
command: <<include(scripts/install_js_dependencies.sh)>>
Becomes this:
- run:
name: Install JS dependencies
command: |
echo hello world
You can see here there is no actual script file included with the orb, the orb is still nothing more than regular CircleCI YAML configuration.
If you want to use actual external scripts, they must be downloaded in the CI environment.
Another trick we use:
- run:
name: Install JS dependencies
environment:
SCRIPT_A: <<include(scripts/some-other-script.sh)>>
command: <<include(scripts/install_js_dependencies.sh)>>
In this example, there is an environment named SCRIPT_A
that contains the other script we want to use, though it is “trapped” in this environment variable. We would still need to evaluate it, or write it to a file in the CI job before we would be able to execute it.
Just keep in mind the include
syntax only literally includes the content of a file in the current location.