Closed svikash4 closed 1 year ago
Hi @svikash4, thank you for the question, the reason why you are getting the error is that you trying to set if else statements in the task inputs, it's working for the Bash task because the syntax if [[ "$(environment)" == "dev" ]]; then
is valid for bash.
In your case you probably need something like this(documentation):
- task: AzureKeyVault@2
inputs:
azureSubscription: 'MemberPortalNonProdServicePrincipalConnection'
KeyVaultName: 'mbr-portal-common-kv'
RunAsPreJob: true
${{ if eq(parameters.environment, 'dev') }}:
SecretsFilter: dev-apim-subscription-key
${{ if eq(parameters.environment, 'prf') }}:
SecretsFilter: prf-apim-subscription-key
${{ if eq(parameters.environment, 'stg') }}:
SecretsFilter: stg-apim-subscription-key
${{ if eq(parameters.environment, 'tst') }}:
SecretsFilter: tst-apim-subscription-key
${{ else }}:
SecretsFilter: default value
This repo is for working in the open on Azure Pipelines YAML features. It's not a great place to make new feature requests, report problems, or get support. Issues you open here may sit unreviewed for a very long time. name: $(Build.BuildNumber).$(Version.Revision)$(Version.Suffix)
trigger:
pool: name: Portal21
parameters:
name: environment displayName: CWP environment type: string default: Please select environment values:
name: region displayName: CWP Region type: string default: Please select environment Central or East values:
variables: Build.BuildNumber: rel23.3.2 Version.Revision: $[counter(variables['Build.BuildNumber'], 0)]
Set the suffix of the version number depending on whether this is master, pr, or other branch
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}: Version.Suffix: "" # master ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: Version.Suffix: "-pr" # pull request ${{ if and(ne(variables['Build.SourceBranch'], 'refs/heads/master'), ne(variables['Build.Reason'], 'PullRequest')) }}: Version.Suffix: "Branch"
steps:
checkout: self
task: UseNode@1 displayName: "Use Node 16.x" inputs: version: "16.19.1"
script: "npm install"
task: Npm@1 inputs: command: "custom" customCommand: run build validate $(Build.Repository.LocalPath)/igniset /subscriptions/MemberPortalNonProdServicePrincipalConnection/resourceGroups/mbr-portal-dev-us-c-rg/providers/Microsoft.DataFactory/factories/configservicedf-dev displayName: Validate
task: Npm@1 inputs: command: custom workingDir: $(Build.Repository.LocalPath) customCommand: run build export $(Build.Repository.LocalPath)/igniset /subscriptions/MemberPortalNonProdServicePrincipalConnection/resourceGroups/mbr-portal-dev-us-c-rg/providers/Microsoft.DataFactory/factories/configservicedf-dev 'ArmTemplate' displayName: Validate and Generate ARM template
task: PublishBuildArtifacts@1 inputs: targetPath: $(Build.Repository.LocalPath)/ArmTemplate PathtoPublish: $(Build.Repository.LocalPath)/ArmTemplate ArtifactName: ArmTemplate
task: AzureKeyVault@1 inputs: azureSubscription: 'MemberPortalNonProdServicePrincipalConnection' KeyVaultName: 'mbr-portal-common-kv' SecretsFilter: | ${{ if eq(parameters.environment, 'dev') }} dev-apim-subscription-key ${{ elseif eq(parameters.environment, 'prf') }} prf-apim-subscription-key ${{ elseif eq(parameters.environment, 'stg') }} stg-apim-subscription-key ${{ elseif eq(parameters.environment, 'tst') }} tst-apim-subscription-key ${{ else }}
bash: | if [[ "$(environment)" == "dev" ]]; then echo "##vso[task.setvariable variable=subscriptionKey;issecret=true]$(dev-apim-subscription-key)" elif [[ "$(environment)" == "prf" ]]; then echo "##vso[task.setvariable variable=subscriptionKey;issecret=true]$(prf-apim-subscription-key)" elif [[ "$(environment)" == "stg" ]]; then echo "##vso[task.setvariable variable=subscriptionKey;issecret=true]$(stg-apim-subscription-key)" elif [[ "$(environment)" == "tst" ]]; then echo "##vso[task.setvariable variable=subscriptionKey;issecret=true]$(tst-apim-subscription-key)" fi displayName: 'Assign Secret Value'
task: AzureResourceManagerTemplateDeployment@3 inputs: ConnectedServiceName: 'Azure Non Prod' azureSubscription: 'MemberPortalNonProdServicePrincipalConnection' ResourceGroupName: 'mbr-portal-${{ parameters.environment }}-us-c-rg' Location: 'Central US' templateLocation: 'Linked artifact' csmFile: '$(Build.Repository.LocalPath)/ArmTemplate/ARMTemplateForFactory.json' csmParametersFile: '$(Build.Repository.LocalPath)/ArmTemplate/ARMTemplateParametersForFactory.json' overrideParameters:
'mbrconfigservicedfbloblink_properties_typeProperties_connectionString_secretName DATAFACTORY-CONNECTION-STRING'
deploymentMode: 'Incremental' StopStartTriggers: true DeployGlobalParams: true
From the Azure Key vault when I am using if/else statment it is failling with the error as directive are not supported for the expression that are embedded within the string Directive are only supported when the entire value is an expression