A team asks to write a `vars/` step that calls Jenkins internal APIs (`Jenkins.instance.getItem`) to list jobs. Should it live in the trusted library?
AdvancedScenarioShared libraries & multibranch
Answer
Situation read → Trusted library code runs unsandboxed; any step there becomes a capability every pipeline gets.
What I'd do →
- Ask what the real need is; often the REST API or a plugin step answers it.
- If needed, implement a narrow step (
listJobsInFolder(folder)) that returns names only, validates input, and checks the caller's folder. - Review it like privileged code; never expose generic "run this Groovy" helpers.
- Prefer doing such admin tasks in a separate admin-only job.
Why → A trusted library is an admin API surface for all Jenkinsfile authors.
Interview tip → Tie it to the principle of least privilege.
More on Shared libraries & multibranch
A shared library change merged to `main` broke 200 pipelines within minutes. How do you prevent a repeat?IntermediateYou want to test a library branch against a real app pipeline without affecting anyone. How?BeginnerEvery app repo has its own pod YAML for builds, and they all drift. How do you standardize?IntermediateSecurity wants every pipeline to run a secret scan, even if teams forget to add it. How?AdvancedA multibranch project has 600 stale branch jobs and the folder page takes 30 seconds to load. What do you do?BeginnerA new org with 150 repositories wants Jenkins builds for every repo with a Jenkinsfile, without tickets to the platform team. What do you set up?Intermediate