admin管理员组文章数量:1356478
In my various pipelines I have been using shared scripts like this:
@Library('SharedScripts') _
def myUtils= new shared.scripts.myUtils()
pipeline{
....
// some stage
myFunction()
}
def myFunction(){
// some computation
myUtils.foo()
}
myUtils.groovy
file resides in src/shared/scripts/
folder and the method myFunction
defined outside of the pipeline block makes some additional computation than call the method foo()
from the myUtils
script.
myUtils
looks like this:
package shared.scripts
def foo(){
//some stuff
}
After the latest Jenkins updates, Jenkins issues a warning with "Did you fet the "def" keyword? "
for my myUtils= new shared.scripts.myUtils()
call. However, def myUtils= new shared.scripts.myUtils()
makes myUtils
unaccessible by the methods defined outside of the pipeline block so I have to move the additional functionality of myFunction
inside the pipeline block.
@Library('SharedScripts') _
myUtils= new shared.scripts.myUtils()
pipeline{
....
// some stage
// myFunction()
// some computation
myUtils.foo()
}
I would rather prefer to keep my myFunction
as it is now, for better visibility and not to have to refactor many of my pipelines.
Is there any other clever workaround so I can keep my method myFunction
defined outside of the pipeline block and still use myUtils
script and also not get the warning about def
keyword ?
In my various pipelines I have been using shared scripts like this:
@Library('SharedScripts') _
def myUtils= new shared.scripts.myUtils()
pipeline{
....
// some stage
myFunction()
}
def myFunction(){
// some computation
myUtils.foo()
}
myUtils.groovy
file resides in src/shared/scripts/
folder and the method myFunction
defined outside of the pipeline block makes some additional computation than call the method foo()
from the myUtils
script.
myUtils
looks like this:
package shared.scripts
def foo(){
//some stuff
}
After the latest Jenkins updates, Jenkins issues a warning with "Did you fet the "def" keyword? "
for my myUtils= new shared.scripts.myUtils()
call. However, def myUtils= new shared.scripts.myUtils()
makes myUtils
unaccessible by the methods defined outside of the pipeline block so I have to move the additional functionality of myFunction
inside the pipeline block.
@Library('SharedScripts') _
myUtils= new shared.scripts.myUtils()
pipeline{
....
// some stage
// myFunction()
// some computation
myUtils.foo()
}
I would rather prefer to keep my myFunction
as it is now, for better visibility and not to have to refactor many of my pipelines.
Is there any other clever workaround so I can keep my method myFunction
defined outside of the pipeline block and still use myUtils
script and also not get the warning about def
keyword ?
1 Answer
Reset to default 2You may want to use @Field
:
@Library('SharedScripts') _
import groovy.transform.Field
@Field def myUtils = new shared.scripts.myUtils()
pipeline{
....
// some stage
myFunction()
}
def myFunction(){
// some computation
myUtils.foo()
}
版权声明:本文标题:groovy - Using methods from shared scripts in methods defined outside pipeline block in jenkins - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744039001a2580309.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论