如何使用Python或Jenkins-Python API重命名詹金斯的工作描述
我正在尝试使用Python更新Jenkins的作业的描述和名称。所以怎么做。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我正在尝试使用Python更新Jenkins的作业的描述和名称。所以怎么做。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
这不是一个非常简单的任务,并且需要您编辑作业config xml文件。
Jenkins API官方仅提供与运行构建相关的有限功能。但是,由于所有Jenkins作业详细信息都存储在
config.xml
中,因此您可以将其用于您的优势。您将必须在Jenkins服务器中运行此脚本,并将其修改config.xml
在Root Jenkins目录中找到。如果要打开此文件,您将看到此处定义的所有作业名称。更改这些将导致提及正在改变的作业。但是,工作本身实际上并没有改变。要实现这一目标,请转到jenkins \ home \ jobs
,并会找到以作业命名的文件夹列表。您必须更改文件夹的名称,以匹配更新的名称。遵循这些步骤后,您将更改工作名称。要更改职位描述,您需要进入以作业命名的单个文件夹。在那里,您会找到另一个
config.xml
。打开此功能,您会找到工作描述。更改此描述将导致更改职位描述。因此,这些是更改作业名称和描述的步骤。所有这些都可以使用Python自动化。此外,您可能需要看一下 jenkinsapi 软件包 package 软件包:
此软件包具有 getConfig 可以获取必要配置文件的函数。在。
This is not a very straightforward task, and will require you to edit the job config XML files.
The official Jenkins API only provides limited functionality related to running builds. However, since all Jenkins job details are stored within the
config.xml
, you can use this to your advantage. You would have to run this script in you Jenkins server, and have it modify theconfig.xml
found in the root Jenkins directory. If you were to open this file, you would see all the job names defined here. Changing those would result in the references to jobs being changed. However, the jobs themselves would not have actually changed. To make that happen, go tojenkins\home\jobs
, and would find a list of folders named after jobs. You have to change the name of the folder to match the updated name as well.Once you have followed these steps, you would have changed the job name. To change the job description, you need to go into the individual folder named after the job. There, you will find another
config.xml
. Open this up and you would find the job description. Changing this description will result in the job description being changed.So those are the steps to changing the job name and description. All of it can be automated using Python. Additionally, you might want to take a look at the jenkinsapi package:
This package has a getConfig function that can get the necessary config files. More on that in this answer.