I need to have my yml file fixed i can't seem to pass variables to the file.
Asked by Isaac Dhibikirwa:

I am not getting the variables passed to the script.

this is the result

Deploy job started

USER: $USER

SERVER:

BRANCH:

ssh: Could not resolve hostname : Name or service not known

And here are the defined variables in my environment.

Workspace variables:

ALPHA

AWS_ACCESS_KEY

AWS_REGION

AWS_SECRET_KEY

BITBUCKET_APP_PASSWORD

BITBUCKET_USERNAME

DEV_SERVER

MS_PROD_SERVER

OMEGA

PROD

PROD_VAULT_PATH

QA_SERVER

REPO_TOKEN SERVER

SONAR_HOST_URL

STAGING

STAGING_SERVER

UAT

UAT_SERVER

USER

VAULT_FILE

VAULT_PATH

And below is the script

```
image: python:3.8.10
 
variables: 
REPO_PATH: "/opt/odoo/odoo-11-updated/custom/copia_addons/copia_commission/" 

definitions: 
steps: 
- &deploy_job_and_common_script 
caches: 
- pip 
script: 
- | echo "Deploy job started" 
    echo "USER: ${USER}" 
    echo "SERVER: ${SERVERS}" 
    echo "BRANCH: ${BRANCH}" 
          ssh ${USER}@${SERVERS} "
          echo 'Connected to server'; 
          cd ${REPO_PATH} && \ 
          sudo chown -R ${USER}:${USER} . && \ 
          git pull origin ${BRANCH} && \ 
          sudo chown -R odoo:odoo . && \  
          sudo systemctl restart erp.odoo.service && \ 
          sudo systemctl status erp.odoo.service" 

pipelines: 
 branches: 
   qa: 
    - step: 
      name: Deploying to QA
      <<: *deploy_job_and_common_script 
      variables: 
        SERVERS: "${QA_SERVER}" 
      
   uat:  
    - step: 
      name: Deploying to UAT 
      <<: *deploy_job_and_common_script 
      variables: 
        SERVERS: "${UAT}" 

   staging: 
     - step: 
       name: Deploying to Staging 
       <<: *deploy_job_and_common_script 
       variables: 
         SERVERS: "${STAGING_SERVER}" 

   master: 
     - step: 
       name: Deploying to Production - ALPHA 
       <<: *deploy_job_and_common_script 
       variables: 
         SERVERS: "${ALPHA}" 

     - step: 
       name: Deploying to Production - OMEGA 
       <<: *deploy_job_and_common_script 
       variables: 
         SERVERS: "${OMEGA}"
```


Answers:
author: Theodora Boudale
body: Hi Isaac and welcome to the community!

I'm afraid that it is not possible to override variables when using YAML anchors, which is why the variables are not substituted.

What you could do is the following:

**1.** First, set up a deployment environment for each step that is deploying from **Repository settings \> Deployments**.

On that page, create five deployment environments named e.g. qa, uat, staging, prodalpha, prodomega.

**2.** It is possible to create variables for a deployment environment. For each environment you are using, create a deployment variable named **SERVERS** with value the corresponding value for each environment.

**3.** In your yml file, remove the following from all the pipelines definitions:

```
variables: 
  SERVERS: "...."
```

and add instead:

```
deployment: uat
```

(replace the value uat with the corresponding environment name for each step).

For example, for the uat pipeline, the definition will look as follows:

```
uat: 
  - step: 
      name: Deploying to UAT 
      <<: *deploy_job_and_common_script 
      deployment: uat
```

The variable **SERVERS**from your script will have the value of the deployment variable for the environment you are running the build.

If you use this solution, you can delete the variables QA_SERVER, UAT, STAGING_SERVER, ALPHA, and OMEGA as they will not be needed.

Please feel free to let me know if this works for you and if you have any questions!

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud