Jenkins Shared Libraries

Preview:

Citation preview

\ Jenkins Shared Libraries

Paolo D'Incau@pdincau

\ DevOps

Teams are cross-functional and have end-to-end responsibility on their products.

\ Not only features!

Teams are also in charge to support production, monitor applications and to create/maintain pipelines that fit their needs best.

\ Jenkins pipelines

With Jenkins you can create pipelines using groovy code.

Deployment becomes developer friendly!

\ Beware duplication

Some steps (e.g. deploy) are very similar across teams: you don’t want each team to reinvent the wheel.

\ Separate concerns

You may want to make some things “opaque” to the teams (e.g. changes in orchestrator version, IP address, …).

\ Shared libraries

You can harness Jenkins Shared Libraries and create a set of functionalities that each team can import and use in their pipelines.

\ Example

Let’s see how we can write a library that each team will use to deploy a given containerised application on a generic orchestrator.

\ Code organisation

\ src and vars

Directory ‘src’ has a standard Java source directory structure. It is added to the classpath when executing your pipelines.

Directory ‘vars’ contains scripts that define global variables accessible from your pipelines.

\ Tips I

\ Serializable

Your classes should implement Serializable when they have state, this is needed in order to allow Jenkins to stop and resume your pipelines properly.

\ Tips II

\ Logging

You can’t log directory using ‘println’ or ‘echo’, you have to pass through ‘steps#echo’ which is available in the pipeline context.

\ Configuration

\ Use

\ Conclusions

Jenkins shared libraries are a wonderful tool if you want to ‘DRY’ some common patterns that emerged in your pipelines.

Remember that you are inside Jenkins, so things may behave a little different from what you think.

www.xpeppers.com

/xpepperssrl@xpeppers

Recommended