jenkins shared libraries

18
\ Jenkins Shared Libraries Paolo D'Incau @pdincau

Upload: xpeppers

Post on 21-Jan-2018

208 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Jenkins Shared Libraries

\ Jenkins Shared Libraries

Paolo D'Incau@pdincau

Page 2: Jenkins Shared Libraries

\ DevOps

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

Page 3: Jenkins Shared Libraries

\ Not only features!

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

Page 4: Jenkins Shared Libraries

\ Jenkins pipelines

With Jenkins you can create pipelines using groovy code.

Deployment becomes developer friendly!

Page 5: Jenkins Shared Libraries

\ Beware duplication

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

Page 6: Jenkins Shared Libraries

\ Separate concerns

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

Page 7: Jenkins Shared Libraries

\ Shared libraries

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

Page 8: Jenkins Shared Libraries

\ 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.

Page 9: Jenkins Shared Libraries

\ Code organisation

Page 10: Jenkins Shared Libraries

\ 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.

Page 11: Jenkins Shared Libraries

\ Tips I

Page 12: Jenkins Shared Libraries

\ 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.

Page 13: Jenkins Shared Libraries

\ Tips II

Page 14: Jenkins Shared Libraries

\ Logging

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

Page 15: Jenkins Shared Libraries

\ Configuration

Page 16: Jenkins Shared Libraries

\ Use

Page 17: Jenkins Shared Libraries

\ 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.

Page 18: Jenkins Shared Libraries

www.xpeppers.com

/xpepperssrl@xpeppers