gpt4 book ai didi

python - Jenkinsfile 语法 - 是否有共享 python 构建步骤的 DRY 示例?

转载 作者:太空宇宙 更新时间:2023-11-04 08:45:45 25 4
gpt4 key购买 nike

我有一个带有共享 python 构建脚本的存储库“A”,我今天在 Jenkins 的各种“执行 shell”构建步骤中运行这些脚本。我从 job-dsl groovy 代码中植入这些步骤/脚本。

在存储库“B”(我的应用程序源代码所在的位置)中使用较新的 Jenkins 2 管道概念,我在这个存储库中的 Jenkinsfile 必须是什么样子才能保持干燥并重用我现有的 python 构建脚本?

我研究了插件“workflow-cps-global-lib”,并尝试在我的 Jenkins master 上设置“Pipeline Libraries”,但是由于这个设置是面向 groovy 的,所以它不只是感觉是正确的方法或我只是没有掌握正确的语法。我找不到关于此特定用例的任何示例。

基本上我只想在我的 Jenkinsfile 中这样做:

  1. 为我的应用克隆我的源代码库 ('B')
  2. 使我的存储库“A”中的共享 python 构建脚本可用
  3. 从各种“执行 shell”步骤执行 python 构建脚本
  4. 等等……

最佳答案

workflow-cps-global-lib是要走的路。在“Manage Jenkins -> Configure System -> Global Pipeline Libraries to use your repository”中安装和设置它。

如果您决定使用 python 脚本而不是 groovy,请将所有 python 脚本放在 (root)/resources 目录中。

在您的 Jenkinsfile 中 - 使用 libraryResource 加载脚本

script = libraryResource 'my_script.py'

并使用它

sh script

关于python - Jenkinsfile 语法 - 是否有共享 python 构建步骤的 DRY 示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40805694/

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