docker - jenkins-pipeline 中 DockerBuilderPublisher 的 cleanupWithJenkinsJobDelete 有什么用?
问题描述
我在 jenkins 管道中使用以下代码来构建 docker 映像并推送到自定义工件注册表。
step([
$class: 'DockerBuilderPublisher',
cleanImages: true,
cleanupWithJenkinsJobDelete: true,
cloud: 'docker-cloud',
dockerFileDirectory: '.',
pushCredentialsId: 'docker-jenkins-credential',
pushOnSuccess: true,
tagsString: "<docker-artifactory-repo>/<imagename>:<imagetag>"
])
有人可以解释选项的cleanupWithJenkinsJobDelete
作用和用途是什么吗?所有可用选项和含义的任何文档链接都会有所帮助。谢谢。
解决方案
我无法找到关于cleanupWithJenkinsJobDelete
.
官方 javadoc: boolean cleanupWithJenkinsJobDelete
DockerBuildPublisher.class
及其所有成员(也是cleanupWithJenkinsJobDelete
)可以在这里找到。不幸的是,没有 javadoc,cleanupWithJenkinsJobDelete
所以我们必须扫描代码以查看它的作用。
如果你责怪这个类,你可以看到这个成员被引入的提交。该提交有一个不错的描述:当 jenkins 剔除作业时从存储库中删除图像的功能。
提交引入了一个新类DockerRunListener,如果cleanupWithJenkinsJobDelete
为真则执行逻辑。
当前的主分支(参见这个:DockerRunListener)禁用了代码部分(在此提交中完成)所以我的猜测是cleanupWithJenkinsJobDelete
什么都不做?
@Override
public void onDeleted(Run<?, ?> run) {
super.onDeleted(run);
List<DockerBuildImageAction> actions = run.getActions(DockerBuildImageAction.class);
for(DockerBuildImageAction action : actions) {
if( action.cleanupWithJenkinsJobDelete ) {
LOGGER.info("Attempting to clean up docker image for " + run);
if( action.pushOnSuccess ) {
// TODO:
/*
DockerRegistryClient registryClient;
try {
Identifier identifier = Identifier.fromCompoundString(action.taggedId);
registryClient = DockerRegistryClient.builder()
.withUrl(identifier.repository.getURL())
.build();
registryClient.registryApi().deleteRepositoryTag("library",
identifier.repository.getPath(),
identifier.tag.orNull());
} catch (Exception ex) {
LOGGER.log(Level.WARNING, "Failed to clean up", ex);
}
*/
}
}
}
cleanupWithJenkinsJobDelete
我检查了 git repo,我可以确认如果设置为 true ,这是执行逻辑的唯一位置。
推荐阅读
- javascript - Vue.js/Laravel:如何在多个组件之间传递数据
- reactjs - 解耦 wagtail 管理前端和后端
- conan - 如何运行“conan init”并禁用有关 GCC ABI (libstdc++11) 兼容性的警告?
- c# - Boxview.LinearGradientBrush 的异常
- qemu - Qemu 从主机应用程序读取来宾 ram
- lisp - 删除common lisp中列表的所有元素的函数?
- javascript - 基于html元素减少计数器
- angular - 来自 JavaScript 客户端的 Azure AD B2C 用户帐户管理
- ruby-on-rails - 在 Rails 6 中为文章添加现有标签
- c# - C#如何将多个文件编译在一起?