簡體   English   中英

檢查詹金斯管道中是否存在文件

[英]Check if a file exists in jenkins pipeline

如果我的 jenkins 工作區中存在目錄並且工作區中的管道步驟“fileExists:驗證文件存在”似乎無法正常工作,我正在嘗試運行一個塊。

我正在使用 Jenkins v 1.642 和 Pipeline v 2.1。 並試圖有這樣的條件

if ( fileExists 'test1' ) {
  //Some block
}

我在管道中還有哪些其他選擇?

if條件中使用fileExists步驟或將返回值分配給變量時需要使用方括號

使用變量:

def exists = fileExists 'file'

if (exists) {
    echo 'Yes'
} else {
    echo 'No'
}

使用括號:

if (fileExists('file')) {
    echo 'Yes'
} else {
    echo 'No'
}

必須使用關鍵字“return”

stage('some stage') {
    when { expression { return fileExists ('myfile') } }
    steps {
           echo "file exists"
          }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM