如何在 Jenkins 作业之间传递大量文本?

发布于 2025-01-10 00:42:14 字数 1375 浏览 0 评论 0原文

我使用的 Jenkins 作业调用下游参数化作业,其参数是 JSON 格式的字符串。

有时,下游作业会失败。错误文本量很大,我认为相关内容是:

Caused by: java.io.IOException: Cannot run program "git" (in directory "/home/user/workspace/MyJob@script"): error=7, Argument list too long

...我认为这告诉我由上游作业填充的下游作业的字符串参数太大。
如果我使用字符串长度手动启动作业和玩具,我可以导致作业成功或失败(出现上述错误),我认为这证实了我的猜测,即字符串参数长度是问题所在。

根据这篇文章,Jenkins 字符串参数的最大长度没有记录或公开,可能是因为它是多个变量的函数,使得实例之间的答案不同:jenkins 字符串参数的字符串长度限制是多少

问题:标准/推荐方法是什么在 Jenkins 作业之间传递长字符串?

我可以想象临时解决方案,例如将 JSON 内容写入下游作业已知位置的文件...或者上游作业将文件路径作为参数传递给下游工作——但我更喜欢使用标准/公认的解决方案而不是临时解决方案。

研究这个问题时,我在如下帖子中遇到了 stash()/unstash()在作业之间传递大量参数 但是 Jenkins Snippet Generator 说 stash()unstash() 用于同一构建中的阶段之间使用 - 这不是我的用途-case:我需要在作业之间传递字符串。

其他类似的帖子建议 archiveArtifacts()archiveArtifacts 命令的文档在 Jenkins 中——但是如何“取消归档”工件呢?在 Jenkins 代码片段生成器的“示例步骤”下拉列表中,我没有看到 copyArtifacts() 或任何其他类似于 archiveArtifacts() 的内容>。

I work with a Jenkins job that calls a downstream parameterized job, whose parameter is a JSON-format string.

Occasionally, the downstream job fails. The volume of error text is substantial, and I think the relevant content is:

Caused by: java.io.IOException: Cannot run program "git" (in directory "/home/user/workspace/MyJob@script"): error=7, Argument list too long

...which I think is telling me that the downstream job's string parameter, populated by the upstream job, is too large.
If I manually launch the job and toy with the string length I can induce job success or failure (with the above error), which I think substantiates my guess that the string parameter length is the problem.

According to this post, the maximum length of a Jenkins string parameter is not documented or publicized, possibly because it is a function of several variables that makes the answer different between instances: what's the string length limit of jenkins string parameter

Question: What are standard/recommended methods of passing long strings between Jenkins jobs?

I can imagine ad hoc solutions, such as writing my JSON content to a file at a location known to downstream jobs...or the upstream job passing the filepath as a parameter to the downstream job -- but I'd prefer to use standard/accepted solutions over ad hoc ones.

Researching the issue, I ran into stash()/unstash() in posts such as this: Pass large amount of parameters between jobs
But the Jenkins Snippet Generator says stash() and unstash() are for use between stages in the same build -- which is not my use-case: I need to pass strings between jobs.

Other posts like this suggest archiveArtifacts(): Documentation on archiveArtifacts command in Jenkins -- but how do you "unarchive" an artifact? In the "Sample Step" drop-down list in my Jenkins Snippet Generator, I don't see copyArtifacts() or anything else that appears to be an analog to archiveArtifacts().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文