我在jenkins管道中使用下面的代码来构建docker image并推送到自定义的artifactory注册表。
step([
$class: 'DockerBuilderPublisher',
cleanImages: true,
cleanupWithJenkinsJobDelete: true,
cloud: 'docker-cloud',
dockerFileDirectory: '.',
pushCredentialsId: 'docker-jenkins-credential',
pushOnSuccess: true,
tagsString: "<docker-artifactory-repo>/<imagename>:<imagetag>"
])谁能解释一下cleanupWithJenkinsJobDelete是做什么的,它有什么用途?所有可用选项和含义的任何文档链接都会很有帮助。谢谢。
发布于 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什么也不做?
@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,我可以确认这是执行逻辑的唯一位置。
https://stackoverflow.com/questions/59196703
复制相似问题