3 # Script to rename Jenkins jobs by searching and replacing a string with a new
6 # Usage: ./rename-jobs <search_string> <replace_string>
8 # For example: aaa-merge-master > aaa-merge-beryllium
9 # ./rename-jobs master beryllium
15 echo -n "Enter system (sandbox|releng): "
17 echo -n "Enter username: "
19 echo -n "Enter api_token: "
22 echo "$username:$password"
24 wget -O jenkins-jobs.xml "https://jenkins.opendaylight.org/$system/api/xml"
26 jobs=$(xmlstarlet sel -t -m '//hudson/job' \
27 -n -v 'name' jenkins-jobs.xml | \
28 grep "$search_string")
30 for job in $(echo "$jobs" | tr "\n" " "); do
31 new_job="${job//$search_string/$replace_string}"
32 echo "Renaming $job to $new_job"
33 #curl --data "newName=${new_job}" "https://$username:$password@jenkins.opendaylight.org/$system/job/${job}/doRename"