Search code examples
bashazure-devopsazure-pipelinesxmlstarlet

Use XMLStarlet in Azure DevOps Bash task


I want to use xmlstartlet within a Bash task in Azure DevOps to edit the below XML.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>

I want to make this code to the below.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <PostFlow name="PostFlow">
        <Request>
            <Step>
                <Name>EV-ExtractParameters</Name>
            </Step>
        </Request>
        <Response/>
    </PostFlow>

But stuck at getting to install XMLstarlet in the build server. Has anyone been able to use this in Azure DevOps Bash task?

I have tried to use an agent demand, but that didn't work.


Solution

  • In the Microsoft Hosted agents the xmlstarlet tool not installed in the machine, so you can't just use it.

    You need to add a Bash task to install the tool, then you can use it.

    Example in the .yaml pipeline to the Bash task:

    -bash: |
      sudo apt-get install xmlstarlet
    

    Then use it with the command xmlstarlet [<options>] <command>.