skip to Main Content
name: $(Version.Major).$(Version.Minor).$(Version.Semantic)
trigger:
  branches:
    include:
      - master
      - feature/*
      - bug/*
parameters:
  - name: host
    type: string
    default: IPC_T1_MSG
    values:
      - IPC_T1_MSG
      - IPC_A1_MSG
      - IPC_T4TC_MSG
  - name: checkserver
    displayName: To check the server if it Tomcat
    type: boolean
variables:
  Version.Major: 1
  Version.Minor: 0
  Version.Semantic: '$[counter(variables[''Version.Major''].variables[''Version.Minor''], 2)]'
stages:
  - stage: Build
    jobs:
      - job: BuildMavenProject
        variables:
          - name: MAVEN_CACHE_FOLDER
            value: $(Pipeline.Workspace)/.m2/repository
          - name: incomingFeedName
            value: P00877-incoming-extralibs
        pool:
          vmImage: ubuntu-latest
        steps:
             - task: MavenAuthenticate@0
               inputs:
                 artifactsFeeds: $(incomingFeedName)
             - task: Bash@3
               inputs:
                 targetType: inline
                 script: >
                   mvn -f pom.xml help:effective-pom -Doutput=effectivePom

                   cat effectivePom | sed 
                   '/<dependency>/I{:A;N;h;/</dependency>/I!{H;bA};/</dependency>/I{g;/b.ing.b/Id}}'
                   | tr -d " tnr"  |  sed
                   's:</dependencies>:</dependencies>n:g' |  sed 
                   's:^.*<dependencies>(.*)</dependencies>.*$:1:g'  | sed $d
                   >mavenCacheKey
               displayName: Generate cache key
             - task: Cache@2
               inputs:
                 key: ./mavenCacheKey
                 path: $(MAVEN_CACHE_FOLDER)
                 displayName: Cache Maven
             - task: Maven@3
               inputs:
                 mavenPomFile: pom.xml
                 goals: 'versions:set'
                 options: -X -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)
                   -DnewVersion=$(Build.BuildNumber)
               displayName: Set version
               
             - ${{ if contains(parameters.host, '_T1_') }}:  
             - task: Maven@3
               inputs:
                 mavenPomFile: pom.xml
                 mavenOptions: '-Xmx3072m'
                 javaHomeOption: JDKVersion
                 jdkVersionOption: '1.8'
                 jdkArchitectureOption: x64
                 publishJUnitResults: true
                 testResultsFiles: '**/surefire-reports/TEST-*.xml'
                 goals: package
               displayName: Compile maven project
             - ${{ if contains(parameters.host, '_T4TC_') }}:        
             - task: Maven@4
               inputs:
                 mavenPomFile: pom.xml
                 mavenOptions: '-Xmx3072m'
                 javaHomeOption: JDKVersion
                 jdkVersionOption: '1.17'
                 jdkArchitectureOption: x64
                 publishJUnitResults: true
                 testResultsFiles: '**/surefire-reports/TEST-*.xml'
                 goals: package
               displayName: Compile maven project            
             - task: CopyFiles@2
               inputs:
                 SourceFolder: $(System.DefaultWorkingDirectory)/target
                 Contents: '*.jar'
                 TargetFolder: $(Build.ArtifactStagingDirectory)
               displayName: Stage Jar files for publishing
             - task: PublishPipelineArtifact@1
               inputs:
                 targetPath: $(Build.ArtifactStagingDirectory)
                 artifact: Binaries
                 publishLocation: pipeline
               displayName: Publish Jar file
  - stage: Deploy_JansTool
    pool: CDaaSLinux
    jobs:
      - job: Deploy_JansTool
        variables:
          KeyVaultSubscription: P00877-KeyVault-SVC-NONPROD
          '${{ if contains(parameters.host, ''_T1_'') }}':
            defaultKeyVaultName: INGOneP00877KvT
            secretsFilter: '*'
            hosts_ini_directory_name: test
            ansible_account: ansible_ibp_test@HG_IAM_00001u7_T@ssz
            CyberAck: P00877-CyberAck-test
          '${{ if contains(parameters.host, ''_A1_'') }}':
            defaultKeyVaultName: INGOneP00877KvA
            secretsFilter: '*'
            hosts_ini_directory_name: accept
            ansible_account: ansible_ibp_acc@HG_IAM_00001u7_A@ssz
            CyberAck: P00877-CyberAck-accept
          '${{ if contains(parameters.host, ''_T4TC_'') }}':
            defaultKeyVaultName: INGOneP00877KvT
            secretsFilter: '*'
            hosts_ini_directory_name: test
            ansible_account: ansible_ibp_test@HG_IAM_00001u7_T@ssz
            CyberAck: P00877-CyberAck-test
            checkserver: true
            
        steps:
          - checkout: self
            fetchDepth: 1
            persistCredentials: true
          - task: AzureKeyVault@1
            displayName: Loading Default Azure KeyVault
            inputs:
              azureSubscription: '${{ variables.KeyVaultSubscription }}'
              KeyVaultName: $(defaultKeyVaultName)
              SecretsFilter: $(secretsFilter)
              RunAsPreJob: true
          - task: CyberArkPwv@1
            displayName: PWV
            name: PWV
            inputs:
              svcConnection: '${{ variables.CyberAck }}'
              accounts: $(ansible_account)
          - task: qetza.replacetokens.replacetokens-task.replacetokens@3
            displayName: Replace Tokens with KeyVault Secrets
            inputs:
              rootDirectory: $(System.DefaultWorkingDirectory)/src/main/resources/
              targetFiles: |
                **/*.yml
                **/*.ini
              keepToken: true
              enableTelemetry: false
          - task: ING-Romania.CDaaSAnsibleRolesInit.custom-build-release-task.PrepareAnsibleRuntime@0
            displayName: Prepare Ansible Runtime
            inputs:
              ansibleConfigFilePath: $(System.DefaultWorkingDirectory)/src/main/resources/ansible.cfg

          - task: Ansible@0
            displayName: execute Deploy_JansToolPB.yml
            inputs:
              ansibleInterface: agentMachine
              playbookPathOnAgentMachine: $(System.DefaultWorkingDirectory)/src/main/resources/Deploy_JansTool_PB.yml
              inventoriesAgentMachine: file
              inventoryFileOnAgentMachine: $(System.DefaultWorkingDirectory)/src/main/resources/ipc/${{variables.hosts_ini_directory_name}}/hosts.ini
              args: '-vvvvv --extra-vars "host=${{parameters.host}}"'
              
          - task: Ansible@0
            displayName: execute Deploy_JansToolPB.yml
            inputs:
              ansibleInterface: agentMachine
              playbookPathOnAgentMachine: $(System.DefaultWorkingDirectory)/src/main/resources/Deploy_JansTool_PB2.yml
              inventoriesAgentMachine: file
              inventoryFileOnAgentMachine: $(System.DefaultWorkingDirectory)/src/main/resources/ipc/${{variables.hosts_ini_directory_name}}/hosts.ini
              args: '-vvvvv --extra-vars "host=${{parameters.host}}"'

error line is from below

- ${{ if contains(parameters.host, '_T1_') }}:  
             - task: Maven@3
               inputs:
                 mavenPomFile: pom.xml
                 mavenOptions: '-Xmx3072m'
                 javaHomeOption: JDKVersion
                 jdkVersionOption: '1.8'
                 jdkArchitectureOption: x64
                 publishJUnitResults: true
                 testResultsFiles: '**/surefire-reports/TEST-*.xml'
                 goals: package
               displayName: Compile maven project
             - ${{ if contains(parameters.host, '_T4TC_') }}:        
             - task: Maven@4
               inputs:
                 mavenPomFile: pom.xml
                 mavenOptions: '-Xmx3072m'
                 javaHomeOption: JDKVersion
                 jdkVersionOption: '1.17'
                 jdkArchitectureOption: x64
                 publishJUnitResults: true
                 testResultsFiles: '**/surefire-reports/TEST-*.xml'
                 goals: package
               displayName: Compile maven project   

So this is the code sinpped I have used, I do not understand why my If condition is giving me error.

/azure-pipelines.yml (Line: 64, Col: 16): Expected at least one key-value pair in the mapping
/azure-pipelines.yml (Line: 76, Col: 62): Expected a mapping
/azure-pipelines.yml (Line: 76, Col: 16): Expected at least one key-value pair in the mapping

I tried to validate pipeline before triggering the pipeline and it shows me this error.

2

Answers


  1. Checked your YAML sample, the cause of the issue could be that the If expression contains extra single quotes. And the indentation of the task inputs fields have issue.

    To solve this issue, you can refer to the following sample:

      - ${{ if contains(parameters.host, '_T1_') }}:          
         - task: Maven@3
           inputs:
           mavenPomFile: pom.xml
           mavenOptions: '-Xmx3072m'
           javaHomeOption: JDKVersion
           jdkVersionOption: '1.8'
           jdkArchitectureOption: x64
           publishJUnitResults: true
           testResultsFiles: '**/surefire-reports/TEST-*.xml'
           goals: package
    

    Update:

    name: $(Version.Major).$(Version.Minor).$(Version.Semantic)
    trigger:
      branches:
        include:
          - master
          - feature/*
          - bug/*
    parameters:
      - name: host
        type: string
        default: IPC_T1_MSG
        values:
          - IPC_T1_MSG
          - IPC_A1_MSG
          - IPC_T4TC_MSG
      - name: checkserver
        displayName: To check the server if it Tomcat
        type: boolean
        default: false
    variables:
      Version.Major: 1
      Version.Minor: 0
      Version.Semantic: '$[counter(variables[''Version.Major''].variables[''Version.Minor''], 2)]'
    stages:
      - stage: Build
        jobs:
          - job: BuildMavenProject
            variables:
              - name: MAVEN_CACHE_FOLDER
                value: $(Pipeline.Workspace)/.m2/repository
              - name: incomingFeedName
                value: P00877-incoming-extralibs
            pool:
              vmImage: ubuntu-latest
            steps:
                 - task: MavenAuthenticate@0
                   inputs:
                     artifactsFeeds: $(incomingFeedName)
                 - task: Bash@3
                   inputs:
                     targetType: inline
                     script: >
                       mvn -f pom.xml help:effective-pom -Doutput=effectivePom
    
                       cat effectivePom | sed 
                       '/<dependency>/I{:A;N;h;/</dependency>/I!{H;bA};/</dependency>/I{g;/b.ing.b/Id}}'
                       | tr -d " tnr"  |  sed
                       's:</dependencies>:</dependencies>n:g' |  sed 
                       's:^.*<dependencies>(.*)</dependencies>.*$:1:g'  | sed $d
                       >mavenCacheKey
                   displayName: Generate cache key
                 - task: Cache@2
                   inputs:
                     key: ./mavenCacheKey
                     path: $(MAVEN_CACHE_FOLDER)
                   displayName: Cache Maven
                 - task: Maven@3
                   inputs:
                     mavenPomFile: pom.xml
                     goals: 'versions:set'
                     options: -X -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)
                       -DnewVersion=$(Build.BuildNumber)
                   displayName: Set version
                   
                 - ${{ if contains(parameters.host, '_T1_') }}:  
                   - task: Maven@3
                     inputs:
                      mavenPomFile: pom.xml
                      mavenOptions: '-Xmx3072m'
                      javaHomeOption: JDKVersion
                      jdkVersionOption: '1.8'
                      jdkArchitectureOption: x64
                      publishJUnitResults: true
                      testResultsFiles: '**/surefire-reports/TEST-*.xml'
                      goals: package
                     displayName: Compile maven project
                 - ${{ if contains(parameters.host, '_T4TC_') }}:        
                   - task: Maven@4
                     inputs:
                      mavenPomFile: pom.xml
                      mavenOptions: '-Xmx3072m'
                      javaHomeOption: JDKVersion
                      jdkVersionOption: '1.17'
                      jdkArchitectureOption: x64
                      publishJUnitResults: true
                      testResultsFiles: '**/surefire-reports/TEST-*.xml'
                      goals: package
                     displayName: Compile maven project            
                 - task: CopyFiles@2
                   inputs:
                     SourceFolder: $(System.DefaultWorkingDirectory)/target
                     Contents: '*.jar'
                     TargetFolder: $(Build.ArtifactStagingDirectory)
                   displayName: Stage Jar files for publishing
                 - task: PublishPipelineArtifact@1
                   inputs:
                     targetPath: $(Build.ArtifactStagingDirectory)
                     artifact: Binaries
                     publishLocation: pipeline
                   displayName: Publish Jar file
      - stage: Deploy_JansTool
        pool: CDaaSLinux
        jobs:
          - job: Deploy_JansTool
            variables:
              KeyVaultSubscription: P00877-KeyVault-SVC-NONPROD
              '${{ if contains(parameters.host, ''_T1_'') }}':
                defaultKeyVaultName: INGOneP00877KvT
                secretsFilter: '*'
                hosts_ini_directory_name: test
                ansible_account: ansible_ibp_test@HG_IAM_00001u7_T@ssz
                CyberAck: P00877-CyberAck-test
              '${{ if contains(parameters.host, ''_A1_'') }}':
                defaultKeyVaultName: INGOneP00877KvA
                secretsFilter: '*'
                hosts_ini_directory_name: accept
                ansible_account: ansible_ibp_acc@HG_IAM_00001u7_A@ssz
                CyberAck: P00877-CyberAck-accept
              '${{ if contains(parameters.host, ''_T4TC_'') }}':
                defaultKeyVaultName: INGOneP00877KvT
                secretsFilter: '*'
                hosts_ini_directory_name: test
                ansible_account: ansible_ibp_test@HG_IAM_00001u7_T@ssz
                CyberAck: P00877-CyberAck-test
                checkserver: true
                
            steps:
              - checkout: self
                fetchDepth: 1
                persistCredentials: true
              - task: AzureKeyVault@1
                displayName: Loading Default Azure KeyVault
                inputs:
                  azureSubscription: '${{ variables.KeyVaultSubscription }}'
                  KeyVaultName: $(defaultKeyVaultName)
                  SecretsFilter: $(secretsFilter)
                  RunAsPreJob: true
              - task: CyberArkPwv@1
                displayName: PWV
                name: PWV
                inputs:
                  svcConnection: '${{ variables.CyberAck }}'
                  accounts: $(ansible_account)
              - task: qetza.replacetokens.replacetokens-task.replacetokens@3
                displayName: Replace Tokens with KeyVault Secrets
                inputs:
                  rootDirectory: $(System.DefaultWorkingDirectory)/src/main/resources/
                  targetFiles: |
                    **/*.yml
                    **/*.ini
                  keepToken: true
                  enableTelemetry: false
              - task: ING-Romania.CDaaSAnsibleRolesInit.custom-build-release-task.PrepareAnsibleRuntime@0
                displayName: Prepare Ansible Runtime
                inputs:
                  ansibleConfigFilePath: $(System.DefaultWorkingDirectory)/src/main/resources/ansible.cfg
    
              - task: Ansible@0
                displayName: execute Deploy_JansToolPB.yml
                inputs:
                  ansibleInterface: agentMachine
                  playbookPathOnAgentMachine: $(System.DefaultWorkingDirectory)/src/main/resources/Deploy_JansTool_PB.yml
                  inventoriesAgentMachine: file
                  inventoryFileOnAgentMachine: $(System.DefaultWorkingDirectory)/src/main/resources/ipc/${{variables.hosts_ini_directory_name}}/hosts.ini
                  args: '-vvvvv --extra-vars "host=${{parameters.host}}"'
                  
              - task: Ansible@0
                displayName: execute Deploy_JansToolPB.yml
                inputs:
                  ansibleInterface: agentMachine
                  playbookPathOnAgentMachine: $(System.DefaultWorkingDirectory)/src/main/resources/Deploy_JansTool_PB2.yml
                  inventoriesAgentMachine: file
                  inventoryFileOnAgentMachine: $(System.DefaultWorkingDirectory)/src/main/resources/ipc/${{variables.hosts_ini_directory_name}}/hosts.ini
                  args: '-vvvvv --extra-vars "host=${{parameters.host}}"'
    
    Login or Signup to reply.
  2. You are getting the errors because you have not indented after your if-statements, the engine expects to run everything one indentation in from the if-statement if it evaluates to true.

    Hence solving your errors for each if-statement would simply be i.e.

    - ${{ if contains(parameters.host, '_T1_') }}:  
      - task: Maven@3 # <-- One indentation in from if-statement
        # Task continues here
    

    When they are currently (in your example) on the same indentation, the engine does not understand what you want to run when the if-statement evaluated to true, hence it is telling you it expected at least one key-pair to be found after the if-statement (one indentation in).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search