Jenkins可以处理gui/non-gui交互式python或java程序吗? [英] Can Jenkins handle an gui/non-gui interactive python or java program?

查看:211
本文介绍了Jenkins可以处理gui/non-gui交互式python或java程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个构建管道,开发人员需要在属性文件中设置一些内容,并使用前端GUI填充该文件.

I want to create a build pipeline, and developers need to set up a few things into a properties file which gets populated using a front end GUI.

我尝试使用python运行示例CLI交互式脚本,该脚本只是询问名称并随后将其打印出来,但Jenkins只是等待了很长时间才被绞死.我看到它要求输入,但是用户无法输入数据.

I tried running sample CLI interactive script using python that just asked for a name and prints it out afterwards, but Jenkins just waited for ages then hanged. I see that it asked for the input, but there was no way for the user to input the data.

编辑:目前正在将Jenkins作为服务运行.还是有人推荐一个好的插件,还是我创建python脚本的方式?

EDIT: Currently running Jenkins as a service..Or is there a good plugin anyone recommends or is it the way I created the python script?

首选项: 我更喜欢使用Python,因为它有点轻巧,但是如果人们在使用其他语言方面取得了成功,我就可以使用.

Preference: I would prefer to use Python because it is a little lightweight, but if people had success with other languages I can comprise.

使用GUI菜单填充数据会很酷,因为我可以使用选项框,下拉菜单并使其精美,但这不是必须的,CLI比我们当前的部署要好得多.

Using a GUI menu to populate the data, would be cool because I can use option boxes, drop down menus and make it fancy but it isn't a necessity, a CLI is considerably better than our current deployment.

顺便说一句,在运行Python 2.7和Java 1.7的Windows 7笔记本电脑上运行所有这些操作

BTW, running all this on Windows 7 laptop running Python 2.7 and Java 1.7

对不起,这篇文章!希望人们能帮助我!

Sorry for the essay! Hopefully people can help me!

推荐答案

对不起,但詹金斯不是交互式应用程序.它是为自动执行而设计的.

Sorry, but Jenkins is not an interactive application. It is designed for automated execution.

获取Jenkins作业(以及从该作业执行的所有内容)的唯一可行方法是使用在作业启动前 填充的作业参数.诚然,用于参数输入的Jenkins GUI并不是最大的功能,但确实可以完成.一旦Jenkins作业在作业开始时收集了作业参数,便可以将这些参数传递给作业期间随时执行的任何内容(Python,shell等).要做到这一点,必须有两件事是正确的:

The only viable way to get input to a Jenkins job (and everything that is executed from that job) is with the job parameters that are populated before the job is started. Granted, Jenkins GUI for parameter entry is not the greatest, but it does the job. Once the Jenkins job collected the job parameters at the start of the job, it can pass those parameters to anything it executes (Python, shell, whatever) at any time during the job. Two things have to be true for that to happen:

  • 您需要在作业开始前 收集所有输入数据
  • 无论您进行什么工作(Python,shell等),都需要能够以交互方式而不是通过命令行来接收其输入.
  • You need to collect all the input data before the job starts
  • Whatever your job calls (Python, shell, etc) need to be able to receive their input not interactively, but through command line.

一个精心设计的脚本应该能够简单地在命令行上接受参数:

A well designed script should be able to simply accept parameters on the command line:

./goodscript.sh MyName是最简单的方法,其中值MyName将存储在脚本的第一个参数$1中.后续命令行参数将在变量$2$3等中可用.

./goodscript.sh MyName will be the simplest way of doing it, where value MyName will be stored in $1 first parameter of the script. Subsequent command line parameters will be available in variables $2, $3 and so on.

./goodscript.sh -name MyName -age 30是一种更好的方法,脚本可以通过在参数值之前指定参数名称来获取多个参数,而不必考虑其顺序.您可以阅读有关使用 getopt 进行此参数传递的方法

./goodscript.sh -name MyName -age 30 will be a better way of doing it, where the script can take multiple parameters regardless of their order by specifying a parameter name before parameter value. You can read about using getopt for this method of parameter passing

以上两个示例均假定goodscript.sh编写得足够好以能够处理那些命令行参数.如果脚本未明确处理命令行参数,则上述操作将无济于事.

Both examples above assume that the goodscript.sh is written well enough to be able to process those command line parameters. If the script does not explicitly process command line parameters, doing the above will be useless.

您可以将一些输出管道"到一个不是专门用来显式处理命令行参数的交互式脚本中:
echo MyName | ./interactivescript.sh会将值MyName传递给interactivescript.sh提供给用户的第一个交互式提示.问题在于您只能将值传递给第一个交互式提示.

You can "pipe" some output to an interactive script that is not designed to handle command line parameters explicitly:
echo MyName | ./interactivescript.sh will pass value MyName to the first interactive prompt that interactivescript.sh provides to the user. Problem with this is that you can only pass a value to the first interactive prompt.

就像我上面说的,您可以使用Jenkins GUI收集各种作业参数(下拉列表,复选框,文本输入).我假设您知道如何使用参数设置Jenkins作业.如果没有,请在作业配置中单击此内部版本已参数化" 复选框.如果您不知道如何进行设置,那就是另一个问题,需要单独解释.

Like I said above, you can use Jenkins GUI to gather all sorts of job parameters (dropdown lists, checkboxes, text entry). I assume you know how to setup Jenkins job with parameters. If not, in the job configuration click "This build is parameterized" checkbox. If you can't figure out how to set this up, that's a different question and will need to be explained separately.

但是,一旦您的Jenkins作业预先收集了所有参数,您就可以在"execute shell" 步骤中引用它们.如果您使用的是Windows,则将它们引用为%PARAM_NAME%,对于Linux,则将其引用为$PARAM_NAME.

However, once your Jenkins job collected all the parameters up front, you can reference them in your "execute shell" step. If you are using Windows, you will reference them as %PARAM_NAME%, and for Linux as $PARAM_NAME.

说明您需要帮助的内容:让脚本接受命令行参数,或者从jenkins作业GUI传递这些命令行参数,我将进一步扩展此答案

Explain what you need help with: getting your script to accept command line parameters, or passing those command line parameters from jenkins job GUI, and I will expand this answer further

这篇关于Jenkins可以处理gui/non-gui交互式python或java程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆