[英]Jenkins: “Execute system groovy script” in a pipeline step (SCM committed)
有沒有辦法從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}"
}
}
}
}
}
生成控制台日志:
[Pipeline] echo
look at this: so_true
[Pipeline] echo
currentBuild.number: 84
單擊任何管道作業左側導航中的“管道語法”鏈接,以獲取可在“全局變量參考”中訪問的一些示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.