- step: &deploy
name: Deploy to $DEPLOYMENT_ENV server
clone:
enabled: false
script:
- pipe: atlassian/ssh-run:0.6.0
variables:
SSH_USER: $DEPLOYMENT_SSH_USER
SERVER: $DEPLOYMENT_SERVER_ADDR
COMMAND: >
#script here
pipelines:
branches:
development:
- step: *deploy
deployment: dev
variables:
DEPLOYMENT_ENV: "dev"
DEPLOYMENT_SSH_USER: $DEV_SSH_USER
DEPLOYMENT_SERVER_ADDR: $DEV_SERVER_ADDR
'test/*':
- step: *deploy
deployment: staging
trigger: manual
variables:
DEPLOYMENT_ENV: "staging"
DEPLOYMENT_SSH_USER: $STAGING_SSH_USER
DEPLOYMENT_SERVER_ADDR: $STAGING_SERVER_ADDR
Hello @Naveen Gabriel and welcome to the Community!
The YAML syntax you have used is slightly wrong. Variables can only be used in pipes and in the script section of the step. It's not possible to use variables as part of the step definition, neither setting the variable value at the YAML file directly.
To create and set values to variables, you need to do it from the workspace, repository or deployment settings. Then those variables will be available in the script section of your step :
pipelines:
default:
- step:
script:
- <script>
- step:
name: Deploy to Test
deployment: Test
script:
- echo $DEPLOYMENT_VARIABLE
For more details and example, the Pipelines - Variables and secrets documentation might be of help.
Thank you, @Naveen Gabriel !
Patrik S
Hi @Patrik S thanks for responding.
But then would it mean I have to repeat deploy step for each environment?
I want to have one script of deployment which should be common for each environment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got a way around it. But still would like you to take a look at it and suggest if I can do anything better on this.
- step: &deploy
name: Deploy to development server
deployment : dev
trigger: automatic
clone:
enabled: false
script: &deploy-script
- pipe: atlassian/ssh-run:0.6.0
variables: &deploy-variables
SSH_USER: $DEV_SSH_USER
SERVER: $DEV_SERVER_ADDR
COMMAND: >
#script
branches:
development:
- step: *deploy
test:
- step:
<<: *deploy
deployment: staging
name: Deploy to staging server for testing
script:
- <<: *deploy-script
variables:
<<: *deploy-variables
SSH_USER: $STAGING_SSH_USER
SERVER: $STAGING_SERVER_ADDR
main:
- step: *build-test-sonarcloud
- step: *check-quality-gate-sonarcloud
fail-fast: false
- step:
<<: *deploy
deployment: staging
trigger: manual
name: Deploy to staging server for smoke test
script:
- <<: *deploy-script
variables:
<<: *deploy-variables
SSH_USER: $STAGING_SSH_USER
SERVER: $STAGING_SERVER_ADDR
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.