使用作业DSL执行python脚本throgh groovy脚本 [英] Excute python script throgh groovy script using job DSL

查看:133
本文介绍了使用作业DSL执行python脚本throgh groovy脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考该文档: https://jenkinsci.github.io/job-dsl-插件/#path/freeStyleJob-steps-python 我试图通过groovy自动配置我的工作. 该工作将执行一个python代码段.像这样:

Referring to the document: https://jenkinsci.github.io/job-dsl-plugin/#path/freeStyleJob-steps-python I am trying to configure my job automatically through groovy. The job will execute a python code piece. Something like this:

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

这是代码段.它将在作业构建步骤中在python脚本之上添加

Here is the code snippet. Which will add above python script in the job build steps

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

它不起作用.请帮忙!

推荐答案

Jenkins DSL'python'指的是发光熊猫" 插件不是 python脚本插件.如果像我一样使用python脚本插件,则应牢记这一点.

Jenkins DSL 'python' refers to the Shining Panda plugin not the python script plugin. This is worth bearing in mind if like me you use the python script plugin.

可悲的是python脚本插件没有API,但是您可以使用configure闭包直接添加此代码.

Sadly the python script plugin doesn't have an API but you can use a configure closure to add this direct.

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

对于我来说,这很简单,我想从脚本中读取内容,或者您​​可以直接添加'command('import os')'

This has worked for me as I like to read from script for simplicity or you could add direct with 'command( 'import os' )'

这篇关于使用作业DSL执行python脚本throgh groovy脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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