Reputation: 164
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/>
Upvotes: 5
Views: 14756
Reputation: 65791
sed
is a stream editor and reads the file line by line. Your pattern spans multiple lines in the file, which is why it never matches.
You should either make sed
read the whole file into the pattern space before attempting the substitution...
sed ':a;N;$!ba; s|<triggers>.*<\/triggers>|<triggers\/>|g' example.xml
... or use another tool (preferably suited for XML files, like xmlstarlet
):
xmlstarlet ed -O -u /triggers -v '' example.xml
Upvotes: 7