是否可以将 Jenkins 自由式作业转换为多配置作业?
我在 Jenkins 中有相当多的自由式作业,我想将它们转换为多配置作业,这样我就可以在一项作业下跨多个平台进行构建。这些作业指定了相当多的构建参数,我希望不必通过创建新的多配置作业来再次手动设置它们。目前,每个作业都将其构建限制在我们一直构建的平台上,我看到的唯一其他选择是克隆现有作业并将限制更改为新平台。这并不理想,因为我需要维护 2 份工作,唯一的区别是目标平台。
我看不到通过用户界面执行此操作的方法,但想知道是否还有其他方法。
I have quite a few free-style jobs in Jenkins that I would like to convert to multi-configuration jobs so I can build across multiple platforms under one job. These jobs specify quite a few build parameters and I would like to not have to set them up manually again by creating new multi-configuration jobs. Each job is currently limiting their builds to the platform we've been building on and the only other option I see is to clone the existing job and change the restriction to the new platform. This isn't ideal as I'll need to maintain 2 jobs where the only difference is the target platform.
I don't see a way to do this via the UI, but wondering if there is another way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,没有办法在 UI 中转换作业类型。您必须编辑作业的 config.xml,或者复制并编辑配置文件并根据编辑的配置创建新作业。
您必须检查自由式和自由式之间的差异
具有您使用的各种设置的多配置作业。可能是这样的
只需将 config.xml 中的顶级元素从
project
更改为matrix-project
即可。如果您编辑现有作业配置,则需要同时执行此操作
Jenkins 离线,或者通过管理告诉 Jenkins 重新加载其配置
詹金斯 -> 从磁盘重新加载配置。
如果您决定创建新职位,上一个问题可能会有所帮助
您弄清楚需要进行哪些编辑。具体来说这个答案描述了如何
上传配置文件以创建新作业。
As far as I know, there's no way to convert the type of job in the UI. You'll have to either edit the job's config.xml, or copy and edit the config file and create a new job based on the edited configuration.
You'll have to check the differences between a free-style and
multi-configuration job with the various settings that you use. It might be as
simple as changing the top-level element in config.xml from
project
tomatrix-project
.If you edit the existing job configuration, you'll need to either do it while
Jenkins is offline, or tell Jenkins to reload its configuration via Manage
Jenkins -> Reload Configuration from Disk.
If you decide to create new jobs, this previous question might be helpful once
you figure out what edits need to be made. Specifically this answer describes how
to upload a config file to create a new job.
对于那些希望从专家转向自由式工作的人来说只是一个注释。
maven2-moduleset
标记更改为project
。rootModule
、goals
、mavenValidationLevel
(应彼此接近)。prebuilders
和postbuilders
合并为builders
。Just a note for those who would wish to switch from maven to freestyle job.
maven2-moduleset
tag toproject
.rootModule
,goals
,mavenValidationLevel
(should be close to each other).prebuilders
andpostbuilders
intobuilders
.我刚刚编写了一个脚本,将大约 10000 个 Jenkins 作业从 Maven 作业类型转换为 Freestyle。请不要盲目使用。您可能会丢失配置选项或最终导致 Jenkins 设置损坏。
Python 部分采用配置 xml 作为参数,并使用转换后的数据覆盖同一文件。我使用以下命令在 Jenkins 文件系统上实时运行此命令:
cd /path/to/jenkins/jobs
find * -maxdepth 2 -name config.xml -exec /path/to/maven2freestyle .py {} \;
再次警告。这可能会破坏你的詹金斯!请保留备份!
I just wrote a script to convert about 10000 Jenkins Jobs from Maven Job Type to Freestyle. Please do not use it blindly. You might lose configuration options or end up in a broken Jenkins setup.
The Python Part takes a config xml as argument and overwrites the same file with the converted data. I ran this live on the Jenkins Filesystem with the following command:
cd /path/to/jenkins/jobs
find * -maxdepth 2 -name config.xml -exec /path/to/maven2freestyle.py {} \;
WARNING Again. This might break your Jenkins! Please keep a Backup!