Search code examples
xmlazure-devopsazure-pipelinesxl-deploy

Adding a variable in xml file


In my azure devops "Publish to XL Deploy" task, I am referring to deployit-manifest.xml file where I need to mention the file path. My file name contains the buildid which changes with every build. How can I add this build id in the filename dynamically in deployit-manifest.xml file :

<ctep.Application name="/MyApp" file="/MyApp/MyApp-1.0.0.0.ear"> 

Thanks for any help


Solution

  • There are other extension tasks you can use to replace variables in your config files, besides Replace Tokens task mentioned by Krzysztof. For example RegEx Find & Replace Task and Magic Chunks task.

    When you use Replace Tokens task or RegEx Find & Replace Task. You need first define a variable in your pipleline to contain your build id value(eg. BuildId).

    enter image description here

    If you need to set the buildid dynamic in your pipeline, you can check here to dynamic set the variable in scripts.

    Then modify your deployit-manifest.xml to tokenize the buildid (wrapped with Token prefix #{ and suffix }#).

    <ctep.Application name="/MyApp" file="/MyApp/MyApp-#{BuildId}#.ear">

    Then config the tasks as below (examples are in Yaml view). And keep other settings as default.

    Replace Tokens task

    - task: qetza.replacetokens.replacetokens-task.replacetokens@3
      displayName: 'Replace tokens in **/deployit-manifest.xml'
      inputs:
        targetFiles: '**/deployit-manifest.xml'
    

    RegEx Find & Replace

    - task: knom.regexreplace-task.regex-replace.RegexReplace@3
      displayName: 'RegEx Find & Replace'        
      inputs:      
        InputSearchPattern: |
          **\deployit-manifest.xml
    
        FindRegex: '(#{.*}#)'
        ReplaceRegex: '$(BuildId)'
    

    You can use either one of above tasks to do the work.