Thanks Reinhold.
In the end I could not find a really flexible way to add "extension points".
Nevertheless, I came out with an alternative with default parameters that 
each job using the common pipeline may override.
My common pipeline named "classicJavaBuild" looks like:

./vars/classicJavaBuild.groovy

def call(Map defaultProvidedParamsMap = [:]) {
>
>     // init default parameters
>     Map defaultMap = [skipSonarParam: false,
>         skipTestsCompileAndExecParam: false,
>         skipDocGenerationParam: false,
>         agentParam: 'linuxWithXvfb']    // can be overriden with any label 
> of a Jenkins node
>     defaultMap << defaultProvidedParamsMap   // override default values 
> with provided ones, so each job can just provide the overriden ones, while 
> mostly relying on the defaults values
>     
>     pipeline {
>         agent { node { label defaultMap.agentParam } }    // the build 
> will only run on nodes (ie slaves) tagged with 'linuxWithXvfb' showing that 
> those builds are quite standard BUT require Xvfb installed on the host
>         environment {
>             MAVEN_CMD = "mvn -U --batch-mode -Dmaven.repo.local=${isUnix() 
> ? '$OLEA_JENKINS_HOME' : '%OLEA_JENKINS_HOME%'}/.m2/repository/ -s 
> ${isUnix() ? '$MAVEN_SETTINGS_XML' : '%MAVEN_SETTINGS_XML%'} "
>         }
>         parameters {
>             booleanParam(defaultValue: defaultMap.skipSonarParam,
>                 description: 'skip Sonar reporting',
>                 name: "skipSonar")
>             booleanParam(defaultValue: 
> defaultMap.skipTestsCompileAndExecParam,
>                 description: 'skip tests execution BUT ALSO TESTS 
> COMPILATION',
>                 name: "skipTestsCompileAndExec")
>             booleanParam(defaultValue: defaultMap.skipDocGenerationParam,
>                 description: 'skip DocGeneration',
>                 name: "skipDocGeneration")
> ....
>

So you can see above how I declare some default values for some parameters 
that each specific job may decide to override.
That more or less solved the problem for me.
As a bonus I should try to pass a groovy closure inside one of those 
parameter to know if it is possible to pass a specific chunk of code, 
defined by a job with some specific needs. If I try it I'll tell you !



def call(Map defaultProvidedParamsMap = [:]) {

On Monday, March 19, 2018 at 6:41:33 PM UTC+1, Francois Marot wrote:
>
> Hello all,
>
> I have switched all my Java build job to use a common declarative 
> pipeline, so in all my JenkinsFile, I have the very simple following 
> content:
>
> @Library('classicJavaBuild') _
>>
>> classicJavaBuild()
>>
>
> and the shared pipeline is defined as:
>
> def call(skipSonarParam = false, skipTestsCompileAndExecParam = false, 
>> skipDocGenerationParam = false, doMavenReleaseParam = false) {
>>    
>>     pipeline {
>>         agent { node { label 'linuxWithXvfb' } } 
>>         
>>         parameters {
>>             booleanParam(defaultValue: skipSonarParam,
>>                 description: 'skip Sonar reporting',
>>                 name: "skipSonar")
>>             booleanParam(defaultValue: skipTestsCompileAndExecParam,
>>                 description: 'skip tests execution BUT ALSO TESTS 
>> COMPILATION',
>>                 name: "skipTestsCompileAndExec")
>>             }
>>           
>>         tools { 
>>             maven 'maven-3' 
>>             jdk 'jdk-8' 
>>         }
>>         
>>         stages {
>>     ......a few stages....
>>
>  
>  
>
> So far everything is fine. But now I have a new project where I would like 
> to "extend" this pipeline:
>
> 1- add a new parameter exclusively in the new project while retaining the 
> common ones
> 2- add a new 'stage' (or maybe a new step in an existing stage).
>
> Is there any way to add extension points to a pipeline in a shared library 
> so that my Jenkinsfile can still benefit from my common pipeline while 
> defining also it's own additions ?
>
> Regards
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/716519f6-1600-4c38-bb51-47ff98f68fe4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to