Skip stages in Jenkins pipeline
By default, there is no way to visualize skipped stages in the Jenkins UI.  See this issue report on the Jenkins JIRA about visualizing skipped stages.
There are a few workarounds that I'm aware of:
You can disable the Groovy sandbox to allow importing the aforementioned class.
You can also use the imperative-when plugin for scripted Pipelines as described in this blog post to add visualization (note that I haven't tested this personally).
Or you can skip the visualization altogether and wrap your build steps in an if clause to conditionally execute them.  You'll see in the Jenkins UI that a stage takes 0ms to execute if it has no steps, so there's at least some indication that it was skipped even if it doesn't explicitly say &quot;skipped&quot;.