user797963
user797963

Reputation: 3027

Jenkins Global Pipeline Library - what's a sane development workflow?

What is a sane development workflow for writing jenkins global pipeline libraries and jenkinsFiles? It's kind of a pain to check in my changes to the global pipeline library and then run a build w/ retry to modify the jenkinsFile, then save the diff if it takes a couple iterations.

Anybody have any recommendations? What do you do?

Upvotes: 1

Views: 245

Answers (2)

Max Cascone
Max Cascone

Reputation: 833

Just based on the small amount of context from your question, I can share what I've learned. YMMV.

  1. Source-control the library and make your changes on a branch. You might need another repo to act as a guinea pig to test the new changes - add @branchname to the library declaration in its Jenkinsfile.
  2. Run and test your code on a Jenkins instance running on your local machine. It may not match exactly your production instance, but it's much closer, and therefore faster feedback, to your local. Also, you don't have to push your changes to test - commit locally, test, un-commit, change, commit, test, repeat. When you are done or need to test on the production instance, push.
  3. Use the Script Console as a Groovy scratchpad to test code in. It's missing a lot of plugins/features, but it's great for throwing together some test code to make sure the basics work.
  4. Create small throwaway pipelines to test bits of functionality that you want to iterate quickly on before putting it in a real pipeline, and that won't work in the script console. This lets you focus on the functionality you're building and not worry about the other bits.
    1. Important note: I know of at least one function that doesn't work in the script console, but works fine in a real pipeline: readJSON. It throws an error as if you're doing something wrong but it's just broken in the console. I'm sure there are others.

I'll come back and add more as i think of it.

Upvotes: 0

StephenKing
StephenKing

Reputation: 37610

There is a 3rd-party unit testing framework for Jenkins pipelines: lesfurets/JenkinsPipelineUnit. This also covers shared libraries and allows you to verify the call stack of your pipeline scripts.

Upvotes: 1

Related Questions