Search code examples
jenkinsjenkins-job-dsl

Create a list view in a subfolder using the job DSL plugin in Jenkins


In Jenkins you can easily create a list view with the Job DSL

listView("myView") {
    jobs {
        regex(".*")
    }
}

but if you try to create a list view within a folder, the folder will be created but not the view

folder("someFolder")

listView("someFolder/myView") {
    jobs {
        regex(".*")
    }
}

Is there a way to accomplish this?


Solution

  • This occurs when a Job DSL performs operations in this order:

    1. Create a folder
    2. Create a view for that folder
    3. Re-create the folder

    The reason this happens is that views live in the config file for a folder. When you re-generate a folder, it deletes any configured views for that folder.

    To fix this issue in my case, I removed any duplicate folder creation so that each folder was only created once.