Pipeline does not replace all "Deployments" variables

Kristjan Ortego
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 8, 2025

I'm having an issue with Pipeline deployment. This is my `yml` file:

pipelines:
  branches:
    staging:
      - step:
          name: Build an app
          image: node:22.0.0
          caches:
            - node
          size: 2x
          script:
            - npm install
            - export NODE_OPTIONS=--max-old-space-size=6144
            - npm run build:staging
          artifacts:
            - dist/**
    - step:
          name: Upload source maps to Sentry
          image: getsentry/sentry-cli:2.40.0
          script:
            - sentry-cli sourcemaps inject --org XXX --project $SENTRY_PROJECT_NAME ./dist
            - sentry-cli sourcemaps upload --org XXX --project $SENTRY_PROJECT_NAME --auth-token $SENTRY_AUTH_TOKEN ./dist
    - step:
          name: Deploy new build to staging droplet
          deployment: staging
          script:
            - rsync -rzO dist/skote/ $SSH_USER@$SSH_SERVER:/home/$WEBSITE/$URL/dist/ --exclude=bitbucket-pipelines.yml
As you can see, there are few variables in there and are defined in these scopes:
  • Deployments
    • staging
      • SSH_SERVER
      • WEBSITE
      • URL
  • Repository variables
    • SSH_USER
    • SENTRY_AUTH_TOKEN
The problem I'm having is that all work well, except the $SENTRY_PROJECT_NAME. The variable while executing pipeline is empty and the pipeline errors out, while ALL other do work.
If I move the variable SENTRY_PROJECT_NAME into `Repository variables`, then it starts to work, but this way the variables are not that well structured, since I wanted to separate them per deployment. Right now I need to add two variables SENTRY_PROJECT_NAME and SENTRY_PROJECT_NAME_STAGING. With Deployments, I can have same variable name and two different strings in it, based on which environment is being used for deployment.
My question is: why is the SENTRY_PROJECT_NAME ignored when it's added into Deployment environment and how to properly utilize it?

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 9, 2025

Hello @Kristjan Ortego ,

and welcome to the Community!

Based on the YAML file you shared, the variable $SENTRY_PROJECT_NAME is being used in a step that is not configured as deployment : 

- step:
          name: Upload source maps to Sentry
          image: getsentry/sentry-cli:2.40.0
          script:
            - sentry-cli sourcemaps inject --org XXX --project $SENTRY_PROJECT_NAME ./dist
            - sentry-cli sourcemaps upload --org XXX --project $SENTRY_PROJECT_NAME --auth-token $SENTRY_AUTH_TOKEN ./dist

In this step configuration we can see it does not have a deployment definition, so no deployment variables will be available in this step. This also explains why it works when you move that variable to repository variable.

That being said, if you want to have more than one step per deployment, you can use the stages feature, which allow you to configure multiple deployment steps to the same environment. Following you can find an example on how this would look like in your YAML file : 

pipelines:
  branches:
    staging:
      - step:
          name: Build an app
          image: node:22.0.0
          caches:
            - node
          size: 2x
          script:
            - npm install
            - export NODE_OPTIONS=--max-old-space-size=6144
            - npm run build:staging
          artifacts:
            - dist/**
      - stage:
          name: Deploy to staging
          deployment: staging #all steps within the stage will have access to the deployment environment variables
          steps:
            - step:
               name: Upload source maps to Sentry
               image: getsentry/sentry-cli:2.40.0
               script:
                - sentry-cli sourcemaps inject --org XXX --project $SENTRY_PROJECT_NAME ./dist
                - sentry-cli sourcemaps upload --org XXX --project $SENTRY_PROJECT_NAME --auth-token $SENTRY_AUTH_TOKEN ./dist
            - step:
               name: Deploy new build to staging droplet
               script:
                 - rsync -rzO dist/skote/ $SSH_USER@$SSH_SERVER:/home/$WEBSITE/$URL/dist/ --exclude=bitbucket-pipelines.yml

I hope this helps! Let us know in case you have any questions.

Thank you, @Kristjan Ortego !

Patrik S

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events