归档构建后如何删除原始的詹金斯构建 [英] How to delete original jenkins build after archiving the build
问题描述
我正在使用下面的Jenkinsfile来创建Maven构建并将其存档.
I am using below Jenkinsfile to create maven build and archive it after.
pipeline {
agent any
stages {
stage('Build') {
steps {
withMaven(maven: 'mvn installed') {
sh "mvn clean package"
}
}
post {
success {
archiveArtifacts 'target/*.jar'
}
}
}
}
将构建文件存档后,将其保存到具有我要使用的jar文件的目标文件夹中.但是,build文件夹还包含包含相同jar的原始com ..文件夹.存档后有什么方法可以删除此com文件夹,因为它只是占用了我服务器中根本没有使用的多余空间.
After archiving the build it gets saved to target folder which has the jar file I want to use. However the build folder also contains the original com.. folder that contains the same jar. Is there any way I can delete this com folder after archiving, because it is just taking extra space in my server that I am not using at all.
我不是要清理工作区,而是要清理builds/< build_no>/archive/文件夹中的原始com文件夹
I am not looking to clean the workspace but rather the original com folder inside the builds/<build_no>/archive/ folder
推荐答案
基于@ dev-joshi的编辑,
Based on @dev-joshi's edit,
不是要清理工作区,而是要清理原始的com文件夹 在builds/< build_no>/archive/文件夹中
not looking to clean the workspace but rather the original com folder inside the builds/<build_no>/archive/ folder
我猜您是指归档工件" 的目标位置,而不是Maven编译步骤输出的./target目录.
I am guessing you are referring to the the target location for the "Archive the artifacts" post-build step and not the ./target directory, output of the maven compile step.
您的答案位于"[X]丢弃旧版本" 选项中
Your answer lies in the "[ X ] Discard old builds" option
与工件保持一致的最大构建数量" [ 1 ]
[如果不为空,则仅保留不超过此数量的构件]
将其设置为[ 1 ]
应该可以实现您的目标.
"Max # of builds to keep with artifacts" [ 1 ]
[if not empty, only up to this number of builds have their artifacts retained]
Setting that to [ 1 ]
should achieve your objective.
如果使用管道,请此S/O答案和
If using a pipeline, this S/O answer and the syntax docs provides the syntax options:
options {
buildDiscarder(logRotator(artifactNumToKeepStr: '1'))
}
您将不得不执行另一个构建以清理现有工件.
You will have to execute another build for the existing artifacts to be cleaned up.
我还建议您设置存档选项:
" [ X ]
仅在构建成功的情况下存档工件"
您不想用部分完成的构建就吹走成功的工件.
I'd also suggest you set Archive option:
"[ X ]
Archive artifacts only if build is successful"
You don't want to blow away successful artifacts with a partially completed build.
也要注意: mvn install
会按照标准的maven规则将生成的工件复制到本地存储库中.那通常是在本地工作空间之外(除非选择[x]专用存储库).然后,您可以运行 mvn clean
删除中间工件(*.jar
等),将您返回到构建前状态.您可以将删除工作空间" 与创建要删除文件的模式"一起使用.达到类似的效果(如果您知道自己在做什么,或者只是完全删除工作区.
Note too: mvn install
will copy the generated artifacts to the local repo, following standard maven rules. That is normally outside the local workspace (unless choosing [ x ] private repo). You can then run mvn clean
to delete the intermediary artifacts (*.class
and *.jar
, etc.) from the local workspace, returning you back to pre-build state. You can use the "Delete workspace" post-build step with "Patterns for files to be deleted" to achieve a similar effect (if you know what you are doing, or to simply remove the workspace entirely.
这篇关于归档构建后如何删除原始的詹金斯构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!