DEV Community

Discussion on: Centralise Jenkins Pipelines configuration using Shared Libraries

Collapse
 
gprasanthkumar profile image
Guddanti Prasanth Kumar • Edited

Hi Juan,

I was trying to implement the same concept into my shared library activities to handle repetition of code.

I am using Jenkins v2.105 and I see some problems when I shifted my stage definition into a shared-library call as below:

Before Update:

ln#01 pipeline {
ln#02   stages {
ln#03     stage('1') {
ln#04       println "I am in stage 1"
ln#05     }
ln#06
ln#07     stage('2') {
ln#08       println "I am in stage 2"
ln#09     }
ln#10   }
ln#11 }

After Update:

ln#01 pipeline {
ln#02   stages {
ln#03     stage('1') {
ln#04       println "I am in stage 1"
ln#05     }
ln#06
ln#07     dynamicStage{
ln#08      param = '2'
ln#09     }
ln#10   }
ln#11 }

vars/dynamicStage.groovy
ln#01 def call(body) {
ln#02   def config = [:]
ln#03   body.resolveStrategy = Closure.DELEGATE_FIRST
ln#04   body.delegate = config
ln#05   body()
ln#06
ln#07   stage('Dynamic Stage') {
ln#08     println "I am in stage ${config.param}"
ln#09   }
ln#01
ln#11 }

Expected Behaviour:

I am in stage 1
I am in stage 2

Execution Result:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 07: Expected a stage @ line 07, column [ColumnNumber].
       dynamicStage {

Is it something that the Jenkins v2.105 doesn't support this?

Collapse
 
vinss1 profile image
Vinss

Any Luck on the shared library that you have implemented?