Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can I access a deployment environment variable within a shell script?

Ahmad Mayahi January 7, 2019

I have a file named `deploy.sh` in the repository and I want to access some pipeline environment variables within the script.

I use the following command in my `bitbucket-pipelines.yml` file:

ssh user@host 'bash -s' < 'deploy.sh'

The `deploy.sh` contains some environment variables that are defined in the pipeline:

echo $TEST_FOLDER_PATH

The `TEST_FOLDER_PATH` defined in the `Test` environment as follows:Screenshot 2019-01-07 at 13.37.13.png

So, the question is, how do I read the `TEST_FOLDER_PATH` within the `deploy.sh` file?

 

 

 

1 answer

0 votes
Kenny MacLeod
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 7, 2019

Shell scripts executed from bitbucket-pipelines.yml can access such environment variables just fine, but they have to be executed as part of the step, e.g.

   script:
- deploy.sh

From your question, it looks like you're trying to execute your script on a remote host, triggered by a Pipeline. The remote host won't have any knowledge of the environment variables set up by pipelines, so you'd need to pass those along as arguments to the remote script invocation some how. Hard to be more specific without knowing what the script does, what the env vars are, etc.

amurashkin November 3, 2019

And what if we executing script remotely using atlassian/ssh-run ?

Attila Berczik November 3, 2021

Were you able to solve this problem? 

Now I am trying to do the same thing. 

Could you help me?

amurashkin November 4, 2021

Need to use something like

ssh user@host 'bash -s' < "deploy.sh $TEST_FOLDER_PATH"

And process it as  parameter in your  deploy.sh

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events