简体   繁体   English

将参数化的构建参数传递给Jenkins中的Jython插件

[英]Passing parameterized build parameter to Jython plugin in Jenkins

I need to 我需要

  • run a parameterized build 运行参数化的构建
  • have Jython script (provided by Jython plugin) to get the parameters (I have defined Jython script as build step in the parameterized build) 有Jython脚本(由Jython插件提供)来获取参数(我已经在参数化构建中将Jython脚本定义为构建步骤)

In a shell script build step params can easily be accessed using env variables. 在shell脚本构建步骤中,可以使用env变量轻松访问参数。 Do I have to do the same in Jython? 我在Jython是否必须做同样的事情? (can I do it at all)? (我完全可以这样做)吗?

I'm not sure about how you can access the variable from Parameterized parameter in Execute Jython script in Build section but if i run the Jython script in Windows (after selecting Execute Windows batch command option from the dropdown list in Build section), it works fine. 我不确定如何从Build部分的Execute Jython script中的Parameterized参数访问变量,但是如果我在Windows中运行Jython脚本(在Build部分的下拉列表中选择Execute Windows batch command选项之后),它可以工作精细。 Check the snapshots below where i have used Parameterized Trigger Plugin for creating a String Parameter and then using the same in Jython script. 检查下面的快照,在这些快照中,我使用了参数化触发器插件来创建字符串参数 ,然后在Jython脚本中使用了它们。 It works fine and displays the value of the variable in output. 它工作正常,并在输出中显示变量的值。

在此处输入图片说明

在此处输入图片说明

Here's the sample script i used for accepting parameter: 这是我用于接受参数的示例脚本:

import sys

for arg in sys.argv:
    print arg 

For *nix environment, you obviously have to select Execute shell in Build section's dropdown list and also change %var% to $var . 对于* nix环境,您显然必须在Build部分的下拉列表中选择Execute shell ,并将%var%更改为$var

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

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