在使用 groovy 和作业 dsl 插件创建 jenkins 作业时添加 'execute python script' 作为构建步骤

Add 'execute python script' as build step while creating a jenkins job using groovy with job dsl plugin

我正在使用 DSL 插件 api 从 groovy 脚本创建 jenkins 作业。我想添加 'Execute python script' 作为詹金斯工作的一个步骤。这是我在 this post:

之后所做的
job('example') {
description('My first job')
displayName('Job DSL Example Project')
properties {
    sidebarLinks {
        // use uploaded image
        link('https://wiki.acme.org/', 'Wiki', '/userContent/wiki.png')
    }
}
steps {
    python{
        command(''' print("Hello")''')
        nature('python')
    }
  } 
}

在生成的作业中,添加的步骤是"Python Builder"步,如下图所示。 相反,我想要 "Execute Python script" 步骤,如下所示。

注意:我已经安装了shining panda插件

Job DSL 仅内置支持 Shining Panda 插件,并将生成 "Python Builder" 构建步骤。 "Execute Python script" 构建步骤由 Python 插件提供。

您可以使用 Configure Block 添加该(或任何其他)构建步骤:

job('example') {
  configure {
    it / 'builders' / 'hudson.plugins.python.Python' {
      command('print("Hello")')
    }
  }
}