有没有办法从SCM提交的管道文件中使用Jenkins"Execute system groovy script"步骤?
如果是,我将如何访问其中的预定义变量(如构建)?
如果不是,我是否能够使用例如共享库插件复制功能?
谢谢 !
您可以将groovy代码放在(始终源控制的)Jenkinsfile的管道中,如下所示:
pipeline {
agent { label 'docker' }
stages {
stage ('build') {
steps {
script {
// i used a script block because you can jam arbitrary groovy in here
// without being constrained by the declarative Jenkinsfile DSL
def awesomeVar = 'so_true'
print "look at this: ${awesomeVar}"
// accessing a predefined variable:
echo "currentBuild.number: ${currentBuild.number}"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
生成控制台日志:
[Pipeline] echo
look at this: so_true
[Pipeline] echo
currentBuild.number: 84
Run Code Online (Sandbox Code Playgroud)
单击任何管道作业左侧导航中的"管道语法"链接,以获取可在"全局变量参考"中访问的一些示例.
| 归档时间: |
|
| 查看次数: |
7064 次 |
| 最近记录: |