How to delete build parameter from all jobs?

Article ID:216688637
1 minute readKnowledge base

Issue

How do i delete a build parameter from all jobs?

Environment

  • CloudBees Jenkins Enterprise

Resolution

You can run the following from the Script Console ($JENKINS_URL/script):

import hudson.model.*

  recurseChildren(Hudson.instance.items)

  def recurseChildren(items) {
    items.each { item ->
      if (item.class.canonicalName != 'com.cloudbees.hudson.plugins.folder.Folder') {
        props = item.getProperty(ParametersDefinitionProperty.class)
        if (props != null) {
          props.getParameterDefinitions().removeAll { 'MY_BUILD_PARAM' == it.name }
        }
      } else {
          recurseChildren(((com.cloudbees.hudson.plugins.folder.Folder) item).getItems())
      }
    }
  }

Replace MY_BUILD_PARAM with the build parameter you want to bulk delete.

This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.