Jenkins: Find out how many jobs have a particular post step

We have long list of jobs. Now we need to add post build step in all of them.

I want to pull a report on how many has post build step and how many doesn't.

1 answer

  • answered 2018-07-11 09:11 Teemu Risikko

    Depends on your post build step I suppose, but for example if you want to list all jobs with FlexiblePublishers that contain ConditionalPublishers, you could do something like that in Jenkins script console (found under Manage Jenkins if you are not aware).

    import org.jenkins_ci.plugins.flexible_publish.FlexiblePublisher
    import org.jenkins_ci.plugins.flexible_publish.ConditionalPublisher
    
    def jobs = []
    
    Jenkins.instance.getItems().each {
      if(it instanceof FlexiblePublisher) {
        def p = it as FlexiblePublisher
        p.publishers.each { 
          if(it instanceof ConditionalPublisher ) {
            jobs.add(job.displayName)
          }
        }
      }
    }
    
    println(jobs)
    

    getItems() lists all of the jobs, and then you can collect those that contain the needed publisher.