首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在jenkins- DockerBuilderPublisher中,cleanupWithJenkinsJobDelete的用途是什么?

在jenkins- DockerBuilderPublisher中,cleanupWithJenkinsJobDelete的用途是什么?
EN

Stack Overflow用户
提问于 2019-12-05 21:53:34
回答 1查看 90关注 0票数 2

我在jenkins管道中使用下面的代码来构建docker image并推送到自定义的artifactory注册表。

代码语言:javascript
复制
step([
                $class: 'DockerBuilderPublisher', 
                cleanImages: true, 
                cleanupWithJenkinsJobDelete: true, 
                cloud: 'docker-cloud', 
                dockerFileDirectory: '.', 
                pushCredentialsId: 'docker-jenkins-credential', 
                pushOnSuccess: true, 
                tagsString: "<docker-artifactory-repo>/<imagename>:<imagetag>"
            ])

谁能解释一下cleanupWithJenkinsJobDelete是做什么的,它有什么用途?所有可用选项和含义的任何文档链接都会很有帮助。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-12-05 22:19:24

我找不到关于cleanupWithJenkinsJobDelete的真正文档。

官方javadoc:boolean cleanupWithJenkinsJobDelete

可以在here中找到DockerBuildPublisher.class及其所有成员(也包括cleanupWithJenkinsJobDelete)。不幸的是,没有用于cleanupWithJenkinsJobDelete的javadoc,所以我们必须扫描代码,看看它做了什么。

如果你责怪这个类,你可以看到这个成员被引入的地方。提交有一个很好的描述:Feature to delete images from repository when jenkins culls the job.

commit引入了一个新的类DockerRunListener,如果cleanupWithJenkinsJobDelete为true,它将执行逻辑。

当前的主分支(参见这个:DockerRunListener)禁用了代码部分(在这个commit中完成),所以我猜cleanupWithJenkinsJobDelete什么也不做?

代码语言:javascript
复制
@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);
                }
                      */
            }
        }
}

我检查了git代码库,如果cleanupWithJenkinsJobDelete设置为true,我可以确认这是执行逻辑的唯一位置。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59196703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档