【问题标题】:Add 'execute python script' as build step while creating a jenkins job using groovy with job dsl plugin在使用带有作业 dsl 插件的 groovy 创建 jenkins 作业时添加“执行 python 脚本”作为构建步骤
【发布时间】:2018-02-01 01:19:59
【问题描述】:

我正在使用 DSL 插件 API 从 groovy 脚本创建 jenkins 作业。我想在詹金斯工作中添加“执行 python 脚本”作为一个步骤。这是我在this 帖子之后所做的事情:

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”步骤,如下图所示。 相反,我想要“执行 Python 脚本”步骤,如下所示。

注意:我已经安装了闪亮的熊猫插件。

【问题讨论】:

  • 图片和屏幕截图可以很好地添加到帖子中,但请确保帖子在没有它们的情况下仍然清晰且有用。 Don't post images of code or error messages. 而是直接将实际代码/消息复制并粘贴到帖子中。
  • 谢谢!我会记住这一点。你能帮我看看我哪里出错了。

标签: jenkins groovy jenkins-job-dsl


【解决方案1】:

Job DSL 仅内置对 Shining Panda 插件的支持,并将生成“Python Builder”构建步骤。 “执行 Python 脚本”构建步骤由 Python 插件提供。

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

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

【讨论】:

  • 非常感谢@daspilker!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多