Interview Prep/Jenkins/Shared libraries & multibranch

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 →

  1. Put the script in resources/scripts/deploy.sh in the library.
  2. Load and run it:
    writeFile file: '.ci/deploy.sh', text: libraryResource('scripts/deploy.sh')
    sh 'bash .ci/deploy.sh'
    
  3. Pass inputs as environment variables with withEnv, not interpolation.
  4. 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.

All Jenkins questions Roadmap: Jenkins

More on Shared libraries & multibranch