Replace xml tag using sed

Viewed 9795

We have a jenkins server with too many jobs and most of the jobs have Build trigger as Poll SCM. I want to remove that trigger for all the jobs. Looking for a easy way to do that. I see that whenever the build trigger property is set the config.xml has this-

<triggers>
    <hudson.triggers.SCMTrigger>
      <spec>
        # poll infrequently and rely on Stash webhooks to trigger builds
        @daily
      </spec>
      <ignorePostCommitHooks>false</ignorePostCommitHooks>
    </hudson.triggers.SCMTrigger>
</triggers>

Whenever the Poll SCM flag is set to false this same element in config.xml is as follows-

 <triggers/>

I am looking for an easy way using sed to replace the above triggers tag with this but am not able to get it using sed.

I tried this from the jobs folder and it does not work-

sudo find . -name "config.xml" -print0 | sudo xargs -0 sed -i '' -e 's|<triggers>.*<\/triggers|<triggers\/>|g'

So basically I want to replace the entire contents of triggers element above along with start and end triggers tag with only this

<triggers/>
1 Answers
Related