jenkinsci/jenkins · error · IllegalStateException

View ' already exists

Error message

View ' already exists

What it means

`CreateViewCommand.run()` after creating the view from XML, resolves its final name via `newView.getViewName()` and checks `jenkins.getView(newName) != null`. If a view with that name already exists, IllegalStateException 'View '<newName>' already exists' is thrown before `addView`.

Source

Thrown at core/src/main/java/hudson/cli/CreateViewCommand.java:65

    }

    @Override
    protected int run() throws Exception {

        final Jenkins jenkins = Jenkins.get();
        jenkins.checkPermission(View.CREATE);

        View newView;
        try {

            newView = View.createViewFromXML(viewName, stdin);
        } catch (Failure ex) {
            throw new IllegalArgumentException("Invalid view name: " + ex.getMessage());
        }

        final String newName = newView.getViewName();
        if (jenkins.getView(newName) != null) {
            throw new IllegalStateException("View '" + newName + "' already exists");
        }

        jenkins.addView(newView);

        return 0;
    }
}

View on GitHub (pinned to 2e228ff40b)

Solutions

  1. Choose a unique view name (override via the argument or edit the XML).
  2. Delete the existing view first (`delete-view <name>`) then recreate.
  3. Check `jenkins.getView(name) == null` before creating in automation.

Example fix

// before:
//   java -jar jenkins-cli.jar create-view All < view.xml  // 'All' exists
//   -> IllegalStateException: View 'All' already exists
//
// after: rename or delete first
//   java -jar jenkins-cli.jar delete-view All
//   java -jar jenkins-cli.jar create-view All < view.xml
Defensive patterns

Strategy: validation

Validate before calling

// Check the view name is free before create-view
if (jenkins.getView(newName) != null) {
    throw new IllegalStateException("View '" + newName + "' already exists");
}

Prevention

When it happens

Trigger: Running `java -jar jenkins-cli.jar create-view <name> < view.xml` where a view named <name> already exists on the root (or targeted) Jenkins.

Common situations: Re-running a create-view script; importing a view whose name matches an existing one; provisioning a default view name repeatedly.

Related errors


AI-assisted analysis of jenkinsci/jenkins@2e228ff40b (2026-08-14). Data as JSON: /api/errors/7d9d7893369cebc2. Report an issue: GitHub.