Jenkis 下游作业找不到上游工件 [英] Jenkis downstream job fails to find upstream artifacts

查看:10
本文介绍了Jenkis 下游作业找不到上游工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该设置用于构建和部署到 Adob​​e AEM.

The setup is used to build and deploy to Adobe AEM.

主构建作业从 git 存储库中提取,构建和打包,运行测试,然后触发应该使用上游作业构建的包的下游作业.

Master Build job pulls from git repository, builds and packages, run the tests and then fires downstream jobs that should use the built packages from upstream job.

问题是下游作业失败并显示以下消息:

The issue is that downstream job fail with the message:

Unable to access upstream artifacts area /var/lib/jenkins/jobs/PROJECTNAME-Master-Branch/builds/2014-10-22_11-33-46/archive. Does source project archive artifacts?

在我看来,下游作业触发的 CopyArtifacts 插件以某种方式在错误位置寻找工件.正确的位置是

It seems to me that somehow CopyArtifacts plugin, triggered by the downstream job, is looking for the artifacts in wrong location. The correct location would be

/var/lib/jenkins/jobs/PROJECTNAME-Master-Branch/workspace/PROJECTNAME-*/**/*.jar,/var/lib/jenkins/jobs/PROJECTNAME-Master-Branch/workspace/PROJECTNAME-*/**/*.zip

然后,它抱怨

java.io.IOException: Expecting Ant GLOB pattern, but saw '/var/lib/jenkins/jobs/PROJECTNAME-Master-Branch/workspace/PROJECTNAME-*/**/*.jar,/var/lib/jenkins/jobs/PROJECTNAME-Master-Branch/workspace/PROJECTNAME-*/**/*.zip'. See http://ant.apache.org/manual/Types/fileset.html for syntax

下游作业从另一个项目复制工件,然后构建是触发此作业的上游构建"或从最新完成构建的工作区复制".没有一个有效.

The downstream job copies artifacts from another project, and then the build was either "Upstream build that triggered this job" or "Copy from workspace of latest completed build". And none works.

有什么想法吗?

推荐答案

TL;DR

您正在尝试使用工件而不先存档它们.
您正在尝试使用绝对路径,但它们应该相对于 $WORKSPACE 和/或存档位置".

您误解了与 Jenkins 相关的工件"的概念.

You are misunderstanding the concept of "Artifacts" as it relates to Jenkins.

Artifacts 是在Archive the Artifacts构建后操作的帮助下在构建之后专门保存的文件.

Artifacts are files that are specifically preserved after the build with the help of Archive the Artifacts post-build action.

构建运行时,它会在以下范围内运行:
$WORKSPACE,通常位于文件系统中
$JENKINS_HOME/jobs/$JOB_NAME/workspace
在那里,您可以拥有 SCM 签出文件夹、临时构建文件、最终构建文件、二进制文件等.

When the build runs, it runs within:
$WORKSPACE, which on filesystem usually resides within
$JENKINS_HOME/jobs/$JOB_NAME/workspace
Inside there, you can have your SCM checkout folders, temporary build files, final built files, binaries, etc.

$WORKSPACE 的内容是 volatile,你不应该依赖它,在构建时间框架之外(下游作业 之外的构建时间框架).$WORKSPACE 的内容在不同的主/从节点之间可能会有所不同,它可以被管理员随时删除,也可以被 SCM update/cleanup/checkout 删除.

The contents of $WORKSPACE is volatile, you should never rely on it, outside of the build timeframe (and downstream jobs are outside of the build timeframe). The contents of $WORKSPACE could be different between different master/slave nodes, it could be deleted at any time by admin, or by SCM update/cleanup/checkout.

了解整个Job只有一个 $WORKSPACE也很重要.

It's also important to understand that there is only one $WORKSPACE for the whole Job.

但是现在请注意您的构建历史记录,该列表中有几个条目,由构建号 (#) 和日期时间戳引用.这些存储在:
$JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID
$BUILD_ID 是构建的日期时间戳,例如 2014-10-22_11-33-46

But now pay attention to your Build History, there are several entries in that list, referenced by build number (#) and date timestamp. These are stored under:
$JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID
with $BUILD_ID being the date-timestamp of the build, like 2014-10-22_11-33-46

$WORKSPACE 包含与 current 或 last 相关的信息(问题是:您永远无法确定它是否是当前" 或 "最后") 构建;
builds 文件夹包含所有过去(保留)构建执行的记录(这构成了您左侧的 Build History 列表),构建.

The $WORKSPACE contains the information relevant to current or last (and the problem is: you can never be sure if it's "current" or "last") build;
The builds folder contains a record of all past (retained) build executions (this is what makes up the Build History list on your left), per build.

默认情况下,它只包含 Jenkins 本身需要的内容:build.xml 副本、changelog 信息、控制台日志.当您转到 URL http://$JENKINS_URL/job/$JOB_NAME/[nn]/ 时,其中 [nn] 是数字作业构建/运行编号 (#),它正在从文件系统上的 builds 文件夹中读取这些信息.

By default, it contains only what Jenkins itself needs: build.xml copy, changelog information, console log. When you go to URL http://$JENKINS_URL/job/$JOB_NAME/[nn]/ where [nn] is a numeric job build/run number (#), it's reading this information from the builds folder on the filesystem.

要保留构建的工件(以避免它们被下一个构建覆盖、消除工作空间或只是为了访问旧构建),您需要归档工件(使用相同的 post-构建具有相同标题的操作).当您归档工件时,您指明要保留 $WORKSPACE 中的哪些文件.当 Jenkins 进行归档时,它会将这些文件(保留 [相对于 $WORKSPACE] 的路径)放入:
$JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID/archive/.
这样,您可以为以前的构建保留多组工件,而不仅仅是 $WORKSPACE 中的最新/最后".

To preserve artifacts of a build (to avoid them being overwritten by the next build, wiped out worskpace, or just to access older builds), you need to Archive the Artifacts (with same post-build action with the same title). When you archive the artifacts, you indicate which files within $WORKSPACE you want to preserve. When Jenkins does the archiving, it will place those files (keeping paths [relative to $WORKSPACE] preserved) into:
$JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID/archive/.
This way, you can have multiple sets of artifacts preserved for previous builds, not just "latest/last" from $WORKSPACE.

为了完整起见,我会提到 Jenkins 的永久链接",例如 http://$JENKINS_URL/job/$JOB_NAME/lastSuccessfulBuild/lastFailedBuild等实际上是文件系统上到保留的 builds/$BUILD_ID 文件夹之一的符号链接.

For the sake of completeness, I will mention that Jenkins's "permalinks", such as http://$JENKINS_URL/job/$JOB_NAME/lastSuccessfulBuild and /lastFailedBuild, etc are in fact symlinks on the filesystem to one of the preserved builds/$BUILD_ID folders.

最后,您可以通过作业配置上的放弃旧构建"复选标记来控制构建运行的数量和保留的工件数量(可以单独配置).默认情况下,都会保留所有内容,但如果您开始保留工件,则需要考虑硬盘空间容量.

Lastly, you control how many build runs and how many artifacts are retained (can be configured separately) through "Discard old builds" checkmark on job configuration. By default, all are retained, but if you start retaining artifacts, you need to think of hard-disk space capacity.

因此,根据上述信息并查看您的错误消息,您现在应该看到 Copy Artifacts 插件正在正确查找 /archive/ 部分下的工件构建.

So with the information above, and looking at your error messages, you should now see that the Copy Artifacts plugin is correctly looking for artifacts under the /archive/ section of a build.

您还应该注意到,Copy Artifacts 插件确实让您在选择要从哪个构建复制时选择当前构建".它具有永久链接(如最后一次成功"或最后一次构建")和特定的构建号,所有这些都转换为 $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID/archive/

You should also notice that Copy Artifacts plugin does not let you pick "current build" when selecting which build to copy from. It has permalinks (like "last successful" or "last build"), and specific build numbers, all of which translate to preserved builds under $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID/archive/

即使是触发此作业的上游构建"也会链接到特定的 $BUILD_ID.

Even "Upstream Build that triggered this job" will link to a specific $BUILD_ID.

Archiving Artifacts 的配置与 $WORKSPACE 相关.
Copy Artifacts 的配置与存档位置"相关,即 $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID/archive/.
由于复制工件"是相对于存档位置"的,而存档位置"是相对于 $WORKSPACE 的,那么出于所有密集目的,两种配置的相对路径可以相同且相对于 <代码>$WORKSPACE

Configuration for Archiving Artifacts is relative to $WORKSPACE.
Configuration for Copy Artifacts is relative to "archive location", that is $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID/archive/.
Since "Copy Artifacts" is relative to "archive location", and "archive location" is relative to $WORKSPACE, then for all intensive purposes, the relative paths of both configurations can be same and relative to $WORKSPACE

  • 首先使用构建后操作归档工件,否则您将无法复制任何内容.
  • First Archive the Artifacts with the post-build action, otherwise you have nothing to copy from.
  1. 如果您的文件位于 $WORKSPACE 的根目录中,则应该是:
    PROJECTNAME-*/**/*.jar,PROJECTNAME-*/**/*.zip
    (注意,这里不是完整路径)
  1. If you have your files in the root of $WORKSPACE, it should be:
    PROJECTNAME-*/**/*.jar,PROJECTNAME-*/**/*.zip
    (Note, not full paths in here)

  • 然后使用 触发此作业的上游构建 进行 Copy Artifacts 选择.

    1. 对于要复制的工件字段,请使用:
      • ** 或空白以复制所有存档的工件,或
      • PROJECTNAME-*/**/*.jar,PROJECTNAME-*/**/*.zip(同归档部分)
    1. For Artifacts to copy field use either:
      • ** or blank to copy all archived artifacts, or
      • PROJECTNAME-*/**/*.jar,PROJECTNAME-*/**/*.zip (same as the archiving section)

  • 如果你不想归档,你可以直接使用$WORKSPACECopy from workspace of latest completed build无论如何你都可以必须确保在下游构建执行时没有第二个上游构建可以运行,否则您可能会从部分构建中获取部分文件,因为如前所述,$WORKSPACE 是可变的.强>

    If you don't want to archive, you can use $WORKSPACE directly, with Copy from workspace of latest completed build, however you must ensure that no second upstream build can run while downstream build is executing, else you risk getting a partial file from a partial build, because as previously explained, $WORKSPACE is volatile.

    • 同样,对于 Copy Artifacts 步骤,在 Artifacts to copy 字段下,使用相对于 $WORKSPACE 的路径,即:
      PROJECTNAME-*/**/*.jar,PROJECTNAME-*/**/*.zip
    • Again, for the Copy Artifacts step, under Artifacts to copy field, use path relative to $WORKSPACE, that is:
      PROJECTNAME-*/**/*.jar,PROJECTNAME-*/**/*.zip

    如果您真的想在不同作业之间复制整个 WORKSPACE,请使用任一

    If you really want to copy the whole WORKSPACE between different jobs, use either

    这篇关于Jenkis 下游作业找不到上游工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆