I agree with Saravanan ... and I would also add that there are other two Jenkins features we use for your case.
The approach we follow is:
- first we try with "when" to run stages conditionally depending on branches/parameters/tags/directory and so on
- when we see many times the same piece of code and we want to DRY, then we use the readTrusted to load a snippet of functionality:
def notifier = evaluate readTrusted('./scripts/jenkins/notifier.groovy')
- when we see many times the same piece of code used across different repositories, then we use the Library approach:
@Library('osirium-...@2.0.1')_