博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jenkins 插件Copy Artifacts + Artifacts to copy
阅读量:6236 次
发布时间:2019-06-22

本文共 5640 字,大约阅读时间需要 18 分钟。

问题及遇到的错误:

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?

Unable to access upstream workspace for artifact copy. Slave node offline?
Error: Failed to copy artifacts from xxxxx with filter: *war

 

精简答案:

You are trying to use artifacts without archiving them first.

You are trying to use absolute paths, but they should be relative to $WORKSPACE and/or "archive location".

完整答案:

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

What are Jenkins Artifacts

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

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.

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.

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

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

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 theBuild History list on your left), per build.

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.

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 $WORKSPACEyou 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.

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.

Solutions to your problem

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.

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/

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

In either of below options

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

Option 1

  • First Archive the Artifacts with the post-build action, otherwise you have nothing to copy from.
    1. If you have your files in the root of $WORKSPACE, it should be:
      PROJECTNAME-*/**/*.jar,PROJECTNAME-*/**/*.zip
      (Note, not full paths in here)
  • Then use Upstream Build that triggered this job for Copy Artifacts selection.
    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)

Option 2

If you don't want to archive, you can use $WORKSPACE directly, with Copy from workspace of latest completed buildhowever 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.

  • Again, for the Copy Artifacts step, under Artifacts to copy field, use path relative to $WORKSPACE, that is:
    PROJECTNAME-*/**/*.jar,PROJECTNAME-*/**/*.zip

Option 3

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

  •  plugin or

 

更多请参考: http://stackoverflow.com/questions/26525034/jenkis-downstream-job-fails-to-find-upstream-artifacts 

转载地址:http://clzia.baihongyu.com/

你可能感兴趣的文章
JVM笔记6-垃圾回收器
查看>>
Java并发编程笔记1-竞争条件&初识原子类&可重入锁
查看>>
工厂+单例模式
查看>>
火爆的在线知识付费,能否缓解你的知识焦虑
查看>>
阿里云ACM英文版上线,论“全局配置”在电商国际化微服务平台建设中的妙用
查看>>
getComputedStyle方法获取元素CSS值
查看>>
关于图片的Base64编码
查看>>
Android加载Gif和ImageView的通用解决方案:android-gif-drawable(1)
查看>>
WPF TextBox/TextBlock 文本超出显示时,文本靠右显示
查看>>
C++的函数对象优于函数指针地方
查看>>
虚拟机上不能使用CUDA
查看>>
Vue + Koa 搭建 ACM OJ
查看>>
java基础学习_基础语法(下)02_day06总结
查看>>
和平之翼代码生成器 SMEU 版 4.0.0 RC 宝船候选版发布
查看>>
浅谈Base64编码算法
查看>>
2016中国“互联网+”千人论坛 ——“互联网业务与技术”分论坛成功举办 聚焦大数据与人工智能...
查看>>
SAP上阿里云FAQ
查看>>
Java中设置Session过期时间(Spring Boot)
查看>>
电子发票时代来临,喜报销打造全新报销方式
查看>>
「镁客·请讲」智周万物何小祥:深挖用户需求,打造一个完整的物联网仓储系统...
查看>>