I'm deploying using an azure-pipelines.yml file and the environment name is not getting resolved in Jira:
The yaml looks like this:
variables:
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/UAT') }}:
- name: environment
value: UAT
jobs:
- deployment: Deploy
environment: $(environment)
You need to use a conditional insertion or template expression for the environment name to resolve in Jira.
Example only using conditional insertion:
jobs:
- deployment: Deploy
environment:
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}:
name: Production
${{ else }}:
name: Development
Unfortunately, template expressions using variables don't seem to work:
variables:
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}:
- name: environment
value: Production
- ${{ else }}:
- name: environment
value: Development
jobs:
- deployment: Deploy
environment: ${{ variables.environment }}
But template expressions using parameters do:
parameters:
- name: targetEnvironment
displayName: Target environment
type: string
default: QA
values:
- QA
- UAT
- Production
jobs:
- deployment: Deploy
environment:
name: ${{ parameters.targetEnvironment }}
THIS IS NOT FIXED! I have the same issue and have tried the same solution as in the answer and it still prints ${{variables.environment}} as the environment on the deployment modal.
Variables
- ${{ if contains( variables['Build.DefinitionName'], 'QA' ) }}:
- name: environment
value: 'QA'
- ${{ elseif endsWith( variables['Build.DefinitionName'], 'Develop' ) }}:
- name: environment
value: 'Develop'
- ${{ elseif endsWith( variables['Build.DefinitionName'], 'Staging' ) }}:
- name: environment
value: 'Staging'
- ${{ elseif endsWith( variables['Build.DefinitionName'], 'Production' ) }}:
- name: environment
value: 'Production'
- ${{ else }}:
- name: environment
value: '$(Build.DefinitionName)'
Deployment
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems that template expressions with variables don't work, but parameters do. Conditional insertion also works at the environment input to the deployment job as shown in my solution.
I've switched all my pipelines over to use an environment parameter because it simplifies our branching strategy. Environment configuration goes in a variable group library that we import with
variables:
- group: environment-${{ parameters.targetEnvironment }}`
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried parameters and it didn't work either. It still prints out $(environment) which is not the name of the parameter I am passing, so I'm not sure where that is coming from.
Jira
YAML
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you passing $(environment) into your template as the environment parameter? The template gets compiled before that variable is resolved in the parent pipeline.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm going to try using the template expression to set the environment parameter directly to see if that resolves my issue. I suspect it will, because azure devops provides an azure-pipelines-expanded.yaml file with each build, and it has already resolved all the template expressions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This did not work. The App is using the pre-rendered pipeline.yml. This is a bug.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I reported the issue to Atlassian using the product feedback button. We'll see if they fix it.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.