如何在Jenkins声明式管道中创建方法? [英] How to create methods in Jenkins Declarative pipeline?
本文介绍了如何在Jenkins声明式管道中创建方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Jenkins声明式管道中有可能吗?如何?
解决方案
更新版本的声明性管道支持此功能,但在2017年中期之前这是不可能的。您可以按照您从Groovy脚本中期望的那样声明函数:
$ b
pipeline {
代理任何
阶段{
阶段('测试'){
步骤{
whateverFunction()
}
}
}
}
void whateverFunction(){
sh'ls /'
}
In jenkins scripted pipeline we are able to create methods and can call them.
Is it possible in the Jenkins declarative pipeline? And how?
解决方案
Newer versions of the declarative pipelines support this, while this was not possible before (~mid 2017). You can just declare functions as you'd expect it from a groovy script:
pipeline {
agent any
stages {
stage('Test') {
steps {
whateverFunction()
}
}
}
}
void whateverFunction() {
sh 'ls /'
}
这篇关于如何在Jenkins声明式管道中创建方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文