A library step needs a 200-line bash script, and escaping it inside Groovy strings is causing bugs. How do you structure it?
BeginnerScenarioShared libraries & multibranch
Answer
Situation read → Groovy string escaping ($, \, quotes) is error-prone.
What I'd do →
- Put the script in
resources/scripts/deploy.shin the library. - Load and run it:
writeFile file: '.ci/deploy.sh', text: libraryResource('scripts/deploy.sh') sh 'bash .ci/deploy.sh' - Pass inputs as environment variables with
withEnv, not interpolation. - Lint the script with ShellCheck in the library's CI.
Why → The script stays a real shell file: testable, lintable, no Groovy escaping.
Interview tip → Mention injection safety as a bonus of env-var passing.
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