Jenkins DSL 自定义配置文件夹

问题描述 投票:0回答:2

我们正在使用 DSL 来构建/设置我们的 Jenkins 结构。 在其中,我们创建文件夹结构,然后创建文件夹中的所有作业。 通过在作业名称中包含文件夹名称,作业最终会位于正确的文件夹中

pipelineJob('folder/subfolder/Job Name') {}

虽然 UI 允许我在文件夹中创建配置文件,但我无法在 dsl groovy 脚本层次结构中找到将自定义配置文件放入文件夹中的方法。

虽然我可以轻松创建配置文件:

configFiles {
  customConfig {
    name('myCustom.yaml')
    id('59f394fc-40fe-489d-989c-7556c1a01153')
    content('yaml content goes here')
  }
}

似乎没有办法将此文件放入文件夹/子文件夹中。

jenkins
2个回答
0
投票

虽然 Job DSL 插件没有提供简单的方法来执行此操作,但您可以使用

configure
直接修改 xml。

folder('Config-File Example') {
    description("Example of a Folder with a Config-File, created via Job DSL")

    configure { folder ->
        folder / 'properties' << 'org.jenkinsci.plugins.configfiles.folder.FolderConfigFileProperty'() { 
            configs(class: 'sorted-set') { 
                comparator(class: 'org.jenkinsci.plugins.configfiles.ConfigByIdComparator')
                'org.jenkinsci.plugins.configfiles.json.JsonConfig'() { 
                    id 'my-config-file-id'
                    providerId 'org.jenkinsci.plugins.configfiles.json.JsonConfig'
                    name 'My Config-File Name'
                    comment 'This contains my awesome configuration data'
                    // Use special characters as-is, they will be encoded automatically
                    content '[ "1", \'2\', "<>$%&" ]'
                } 
            } 
        } 
    } 
}

0
投票

这对我有用:

folder("My-Sweet-Folder") {
    description "Has folder-level config files"

    properties {
        folderConfigFiles {
            configs {
                customConfig {
                    id("dummy-test")
                    name("dummy-test")
                    comment("hello~")
                    content("Config file content")
                }
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.