GoogleContainerTools/jib · error · IllegalArgumentException

jib.to.tags contains empty tag

Error message

jib.to.tags contains empty tag

What it means

After resolving tags, getTags validates that no tag string is empty and throws IllegalArgumentException if any element of jib.to.tags is the empty string. Empty tags are invalid image references and would fail later at reference parsing, so Jib fails fast at configuration time.

Source

Thrown at jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/TargetImageParameters.java:85

    this.image.set(image);
  }

  @Input
  @Optional
  public Set<String> getTags() {
    String property = System.getProperty(PropertyNames.TO_TAGS);
    Set<String> tagsValue;
    if (property != null) {
      tagsValue = ImmutableSet.copyOf(ConfigurationPropertyValidator.parseListProperty(property));
    } else {
      try {
        tagsValue = tags.get();
      } catch (NullPointerException ex) {
        throw new IllegalArgumentException("jib.to.tags contains null tag");
      }
    }
    if (tagsValue.stream().anyMatch(str -> str.isEmpty())) {
      throw new IllegalArgumentException("jib.to.tags contains empty tag");
    }
    return tagsValue;
  }

  public void setTags(List<String> tags) {
    this.tags.set(tags);
  }

  public void setTags(Set<String> tags) {
    this.tags.set(tags);
  }

  public void setTags(Provider<Set<String>> tags) {
    this.tags.set(tags);
  }

  @Nested
  @Optional

View on GitHub (pinned to fb949e2676)

Solutions

  1. Filter out empty strings: tags.findAll { !it.isEmpty() } before assignment
  2. Give the CI variable a default: ${TAG:-latest} or Gradle equivalent
  3. Validate the variable is non-empty in the build script before composing jib.to.tags
  4. Correct the literal list to remove empty entries

Example fix

// before
jib.to.tags = ['latest', System.getenv('TAG') ?: ''] // empty when TAG unset
// after
jib.to.tags = ['latest', System.getenv('TAG')].findAll { it != null && !it.isEmpty() }
Defensive patterns

Strategy: type-guard

Validate before calling

def rawTags = jib.to.tags.orNull ?: []
if (rawTags.any { !(it?.trim()) }) {
  throw new GradleException('jib.to.tags must not contain empty tags')
}

Type guard

static boolean allTagsNonEmpty(List<String> tags) {
  tags != null && tags.every { it != null && !it.isEmpty() }
}

Try / catch

try {
  def tags = targetImageParameters.tags
} catch (IllegalArgumentException e) {
  if (e.message.contains('empty tag')) {
    logger.error('Remove empty strings from jib.to.tags; give CI vars defaults')
  } else { throw e }
}

Prevention

When it happens

Trigger: Configuring `jib.to.tags = ['latest', '']` — e.g. an empty CI variable like TAG="" interpolated into the list — then calling getTags(); also jib.to.tags from a list property where an entry is blank.

Common situations: CI environment variables (git tag, build number) being empty and passed straight into jib.to.tags; trailing comma artifacts in list properties; user typo leaving an empty string literal in the list.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06). Data as JSON: /api/errors/b2bcc3d06eb690ff. Report an issue: GitHub.