diff --git a/pkg/executor/build.go b/pkg/executor/build.go index 8e1743267..e95317ca5 100644 --- a/pkg/executor/build.go +++ b/pkg/executor/build.go @@ -416,9 +416,9 @@ func (s *stageBuilder) build() error { if isCacheCommand { v := command.(commands.Cached) layer := v.Layer() - if (files != nil || layer == nil) && len(files) == 0 { - // a cache image with a layer with no files indicates that no files were changed, ie. by 'RUN echo hello' - // a cache image without a layer indicates that no files were changed too, ie. by 'WORKDIR /' + if layer == nil || (files != nil && len(files) == 0) { + // a cache image without a layer indicates that no files were changed, ie. by 'WORKDIR /' + // a cache image with a layer with no files indicates that no files were changed too, ie. by 'RUN echo hello' logrus.Info("No files were changed, appending empty layer to config. No layer added to image.") } else { if err := s.saveLayerToImage(layer, command.String()); err != nil {