我正在使用腳本化管道并嘗試將我的舞臺放在如下函式中。
node{
if(value=="true")
{
def func(){
stage ('first stage')
}
}
fun() #calling it here.
}
它不作業。它說這里不需要方法定義
此處不需要方法定義。請在適當的位置定義方法,或者嘗試使用塊/閉包。
. 這個怎么做?由于管道在特定節點上運行,因此無法定義外部節點塊。
uj5u.com熱心網友回復:
在不執行階段的情況下,您可以從函式回傳階段配置。請參考以下內容。
node {
stage('Stage 1') {
echo "This stage executed always"
}
def value = true
// Lets execute stage 2
if(value == true) {
generateStage("Stage 2").call()
}
stage('Stage3') {
echo "Stage 3"
}
}
def generateStage(name) {
return {
stage("Stage ${name}") {
echo "Stage ${name}"
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/492767.html
