Azure DevOps deployment environment name variable not resolved

Carlin Scott March 29, 2024

I'm deploying using an azure-pipelines.yml file and the environment name is not getting resolved in Jira:

msedge_KN47AB0lkq.png

The yaml looks like this:

variables:
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/UAT') }}:
- name: environment
value: UAT

jobs:
- deployment: Deploy
  environment: $(environment)
That variable is resolved properly by Azure DevOps (ADO) as part of the build, but from looking at the webhook call ADO made to the Jira app, it wasn't included. I'm guessing the app looked at my azure-pipelines.yml file and extracted the value directly. But maybe something else happened?
The environment name is UAT and I haven't explicitly mapped it to an environment type; I kind of hoped UAT would already be mapped to Staging. Regardless, I expected the name to still show in Jira correctly.

3 answers

1 accepted

0 votes
Answer accepted
Carlin Scott April 4, 2024

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 }}

 

0 votes
Chelsea Saffold
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!
October 1, 2024

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' ) }}:

    - nameenvironment

      value'QA'

  - ${{ elseif endsWith( variables['Build.DefinitionName'], 'Develop' ) }}:

    - nameenvironment

      value'Develop'

  - ${{ elseif endsWith( variables['Build.DefinitionName'], 'Staging' ) }}:

    - nameenvironment

      value'Staging'

  - ${{ elseif endsWith( variables['Build.DefinitionName'], 'Production' ) }}:

    - nameenvironment

      value'Production'  

  - ${{ else }}:

    - nameenvironment

      value'$(Build.DefinitionName)'

Deployment

deploymentEmailSenderDeploy
    displayNameDeploy Email Sender
    environment${{variables.environment}}
Modal 

Screenshot 2024-10-01 155059.png
Carlin Scott October 2, 2024

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 }}`

 

Chelsea Saffold
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!
October 3, 2024

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

-VNT-12916-Improve-Jira-Environments-for-Azure-Devops-App-Jira-10-03-2024_04_00_PM.png

YAML

parameters:
  - name: subscription
    type: string
  - name: jobName
    type: string
    default: 'deploy'
  - name: jobDisplayName
    type: string
    default: 'Deploy'
  - name: containerRegistry
    type: string
  - name: repository
    type: string
  - name: appName
    type: string
  - name: tag
    type: string
  - name: deploymentEnvironment
    type: string

jobs:
  - deployment: ${{ parameters.jobName }}
    displayName: ${{ parameters.jobDisplayName }}
    environment: ${{ parameters.deploymentEnvironment }}
    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzureWebAppContainer@1
            displayName: Deploy Image to Function App
            inputs:
              azureSubscription: ${{ parameters.subscription }}
              appName: ${{ parameters.appName }}
              containers: ${{ parameters.containerRegistry }}/${{ parameters.repository }}:${{ parameters.tag }}
Carlin Scott October 3, 2024

Are you passing $(environment) into your template as the environment parameter? The template gets compiled before that variable is resolved in the parent pipeline.

0 votes
Carlin Scott March 29, 2024

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.

Carlin Scott April 1, 2024

This did not work. The App is using the pre-rendered pipeline.yml. This is a bug.

Carlin Scott April 2, 2024

I reported the issue to Atlassian using the product feedback button. We'll see if they fix it.

Carlin Scott April 4, 2024

They fixed it.

Suggest an answer

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

Atlassian Community Events