如何在 jenkins 中使用 groovy 脚本为配置文件提供程序插件添加配置文件

How to add config file for config file provider plugin with groovy script in jenkins

我正在使用 Job DSL in Jenkins. There is a seed job that generates some files that should be shared across other jobs that could run on different nodes. If the files were not generated, the config files provider plugin 可用于此任务。但是我需要这些文件是动态的,这样就不需要 Jenkins UI 交互。

是否可以使用 groovy 脚本将文件添加到插件?

我能想到的唯一其他选择是记录 UI 交互并让脚本使用修改后的数据重播它。如果 Jenkins 更安全,这还需要获得正确的身份验证和 CSRF 令牌。

当您使用 job-dsl 时,您可以从 Groovy 运行时可以访问的任何地方读取数据。

您可以将共享配置存储在脚本本身的硬编​​码变量中。

您可以通过 Jenkins 参数将数据注入您的种子作业。

您可以从存储种子作业的 git 存储库中的文件中检索数据。

您可以从数据库 REST API 中检索数据。

等等等等

您可以使用 Job DSL 创建由 Config File Provider 插件管理的配置文件:

configFiles {
    customConfig {
        id('one')
        name('Config 1')
        comment('lorem')
        content('ipsum')
        providerId('???')
    }
}

https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-DSL-Commands#config-file