简体   繁体   English

如何使用python使用文件参数启动参数化jenkins作业

[英]How to start a parametrized jenkins job with a file parameter using python

Scenario: I want to start a jenkins job with file parameters, using python to trigger the job.场景:我想用文件参数启动一个 jenkins 作业,使用 python 来触发作业。

Using使用

from jenkinsapi.jenkins import Jenkins

J = Jenkins('http://localhost:8080')

params = {'VERSION': '1.2.3', 'PYTHON_VER': '2.7'}

J.build_job('foo', params)

works for string parameters, but how do I use this if I need a file parameter?适用于字符串参数,但如果我需要文件参数,我该如何使用它?

Can anybody help me please?有人可以帮我吗?

Yes @markus-m you are right that with Build Parameter plugin you can build a job with file as a parameter.You can provide this file to browser and Jenkins will run your job accrodingly, However please find below my comments.是的@markus-m 你是对的,使用 Build Parameter 插件你可以构建一个带有文件作为参数的工作。你可以将此文件提供给浏览器,Jenkins 将按顺序运行你的工作,但是请在我的评论下方找到。

The file you are passing as an argument must be placed in your Jenkins workspace so that Jenkins can access and run this file.您作为参数传递的文件必须放在您的 Jenkins 工作区中,以便 Jenkins 可以访问和运行此文件。 The same file name can also be accessed with Jenkins environment variables.也可以使用 Jenkins 环境变量访问相同的文件名。

For your scenario, you have two solutions对于您的场景,您有两种解决方案

  1. Copy the file that you want to pass as parameter to Jenkins Workspace, so that when you run your job with file location, Jenkins will upload the file and Run accrodingly.将您要作为参数传递给 Jenkins Workspace 的文件复制,以便当您使用文件位置运行您的作业时,Jenkins 将上传文件并按顺序运行。

  2. you can access Jenkins with Remote API's so that you can run CURL Command and pass file as parameter.您可以使用远程 API 访问 Jenkins,以便您可以运行 CURL 命令并将文件作为参数传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM