I am studying Jenkins Pipeline Global Lib functionality. It seems pretty handy however due to its global nature any harmful change will affect all the jobs. Thus I want to be able to test it before pushing to master on a different branch.
Is there a way to specify a branch from which I want to to include the global lib sources for a particular job?
UPDATE. I tried a workaround with direct git clone
from the test branch then load
my library file explicitly replacing the automatically loaded one.
The problem comes when this lib uses some other class from the src/
. Because in this case its pre-loaded version from master is always used.
So in the conditions below it runs common.groovy from feature-test but prints Hello from master!!!!
when b.dummy()
is called.
Pipeline Script in Jenkins:
node('myhost'){
git url: 'ssh://10.0.0.1:12345/workflowLibs.git',
branch: 'feature-test'
dir ('src'){
load 'com/foo/Base.groovy'
}
dir ('vars'){
common = load 'common.groovy'
}
}
println common.dummy()
vars/common.groovy (feature-test):
package com.foo
def dummy(){
def b = new com.foo.Base()
b.dummy()
}
src/com/foo/Base.groovy (master):
package com.foo
def dummy(){
return 'Hello from master!!!!'
}
src/com/foo/Base.groovy (feature-test):
package com.foo
def dummy(){
return 'Hello from feature-test!!!!'
}