Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to set bash directory for script

Shlomo Heigh April 15, 2025

I'm trying to create a custom Pipe that creates a bash script in the 

BITBUCKET_PIPE_STORAGE_DIR directory which a later step in the pipeline can call. I am creating two files in the directory: a script file, and a data file which the script will read from. However, when I try to run the script in the later step, I run into an issue where even if I run the script from it's containing directory, it can't read the data file which is next to it in the same directory. It seems that the script is always using some temp directory as the working directory, even when using `dirname "$0"`.
# Ideally this would be `cd BITBUCKET_SHARED_STORAGE_DIR/...` but that env var isn't available, so we need to hardcode the path:
$ cd /opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/my-org/custom-pipe-name
$ ls
> script.sh data
$ . ./script.sh
> bash: /opt/atlassian/pipelines/agent/tmp/data: No such file or directory
 

The script file contains the following code:

#!/usr/bin/env bash
set -a
path="$(dirname "$0")"
source "$path/data"
set +a

 

2 answers

0 votes
Shlomo Heigh April 17, 2025

I'm thinking that this limitation may be why the vault-secrets pipe uses `eval`, which is generally bad practice, instead of loading it's data file directly:

https://bitbucket.org/atlassian/vault-secrets/src/8b0fa1e1d0f4e35bfc5e3665b99b1df061456553/pipe/pipe.py#lines-122

0 votes
Shlomo Heigh April 17, 2025

CC @Igor Stoyanov (b/c I saw you answered some related questions)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events