Groovy is by far the best way to bulk update jobs. You may need to dig into the jenkins / plugin APIs a bit to find out what API calls you need to make, but the script console ( http: // yourJenkinsUrl / script ) provides an easy way to play around with the code until you get it right.
First, you can add / remove steps after the build by calling the getPublishersList() method for the job, and then calling the add / remove methods.
def publishersList = Jenkins.instance.getJob("JobName").getPublishersList() publishersList.removeAll { it.class == whatever.plugin.class } publishersList.add(new PluginConstructor())
If you are not sure which publisher class you want to remove the workspace from, I would suggest manually adding the necessary configurations to one job and then running getPublishersList() from the script console for this job. You will see the class you are working with in the list, and then you can look at the API to see what it takes to create it.
Then you can view all your assignments and add a publisher by doing something like this:
Jenkins.instance.getView("All Jobs").items.each { job -> //Maybe some logic here to filter out specific jobs job.getPublishersList().add(new PluginConstructor()) }
Alternatively, you can use the Jenkins CLI API or the REST API, but to update the actions after the build, you will have to modify the project configuration XML file (which is not a trivial programmatic way) and then overwrite the job configuration using the new configuration file .
Theellis
source share