gpt4 book ai didi

jenkins - 如何使用 File 参数作为参数触发下游 jenkins 作业?

转载 作者:行者123 更新时间:2023-12-01 11:32:58 29 4
gpt4 key购买 nike

我有一个 Jenkins 作业,它接受一个文件作为参数,并使用我想触发下游项目的相同文件。我该怎么做 ? jenkins 似乎不支持将文件作为参数传递给下游项目。我正在使用“在其他项目上触发/调用构建”来触发下游项目。

最佳答案

使用 Parameterized Trigger Plugin但请注意以下事项:

文件参数帮助如下:

The name of the submitted file is available in the environment variable whose name is the same as file location. For example, if you set the file location to be abc.zip [UPLOADED_FILE], then ${abc.zip} [${UPLOADED_FILE}] would give you the original file name passed from the browser (such as my.zip.) The name will not include the directory name portion.



[我的删除线和补充。]

不幸的是,这在不止一个方面是错误的(使用 Jenkins v1.609.1):
  • 成为环境变量名的文件名 abc.zip 是错误的。
  • 如果“文件位置”字段中有目录名部分,它是 包含在变量的名称中。

  • 为什么这些都是坏的?

    好吧,后者与内联帮助相反,两者都可能导致意外结果(在我的情况下确实如此),因为 '.'根据 IEEE Std 1003.1, 2013 Edition:,和 '/' 不是变量名中的标准化字符

    Environment variable names used by the utilities in the Shell and Utilities volume of POSIX.1-2008 consist solely of uppercase letters, digits, and the ( '_' ) [...]



    另见 Robert Gamble's answer to Allowed characters in linux environment variable names .

    所以,答案是:
  • 不要在 File Parameter → File Location 中使用路径或扩展名,例如使用刚刚上传_文件
  • <您的上游项目> → 配置 → 添加构建后操作 → 在其他项目上触发参数化构建
    → 添加参数 → 预定义参数 → 参数:

    KEY=value pairs, one per line (Java properties file format). [...]

    Current build parameters and/or environment variables can be used in form: ${PARAM} or $PARAM.



    长话短说。这会将文件的绝对名称传递给您的下游项目:
    ENV_VAR_IN_DOWNSTREAM_PROJECT=${WORKSPACE}/${UPLOADED_FILE}

  • 更新

    我创建了一个相应的问题: [JENKINS-28996] Environment variable name created from File Parameter → File Location contains the "directory name portion" though stated differently in its inline help

    关于jenkins - 如何使用 File 参数作为参数触发下游 jenkins 作业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30666529/

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