gpt4 book ai didi

python - 使用作业DSL通过groovy脚本执行python脚本

转载 作者:太空宇宙 更新时间:2023-11-03 16:03:25 24 4
gpt4 key购买 nike

引用文档: https://jenkinsci.github.io/job-dsl-plugin/#path/freeStyleJob-steps-python我正在尝试通过 groovy 自动配置我的工作。该作业将执行一段 python 代码。像这样的事情:

import os
from Reporting.MSTest import MSTest
jsonFile = os.path.join(os.getenv('temp')

这是代码片段。这将在作业构建步骤中添加上面的 python 脚本

# the job name is "jobName"
jobA = freeStyleJob("jobName")
jobA.with {
steps {
python {
command(String 'import os')
}
}
}

它不起作用。请帮忙!

最佳答案

Jenkins DSL“python”指的是 Shining Panda插件不是 python script插入。如果您像我一样使用 python 脚本插件,那么这一点值得牢记。

遗憾的是,Python 脚本插件没有 API,但您可以使用配置闭包直接添加它。

configure { node ->
node / builders / 'hudson.plugins.python.Python' / command << readFileFromWorkspace('<script location>')
}

这对我有用,因为为了简单起见,我喜欢从脚本中读取内容,或者您​​可以直接使用“command('import os')”添加

关于python - 使用作业DSL通过groovy脚本执行python脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40084145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com