Stage 阶段的 Jenkinsfile 条件

Jenkinsfile conditions in Stage phase

是否可以在 Jenkins 文件的 Stage 阶段定义多个条件?
让我解释一下我的问题:我只想在条件有效时在我的 Jenkins 管道中发布 Html:

        stage(Documentation)
       {
        agent any
        steps 
        {
         sh"./documents.sh "     //This generate the documentation of several modules

         if(firstModule) { //Is it possible to publishHTML only if documentation of this module was generated???

             publishHTML (target: [
              allowMissing: false,
              alwaysLinkToLastBuild: false,
              keepAll: true,
              reportDir: "${env.WORKSPACE}/firstModule//html",
              reportFiles: 'index.html',
              reportName: "Fist Module Documentation"
            ])

         }

         if(secondModule) { //Is it possible to publishHTML only if documentation of this module was generated???                            
         publishHTML (target: [
              allowMissing: false,
              alwaysLinkToLastBuild: false,
              keepAll: true,
              reportDir: "${env.WORKSPACE}/secondModule/html",
              reportFiles: 'index.html',
              reportName: "Second Modul Documentation"
            ])
         }
     }

我不知道 firstModule 是否构建...这就是我想知道的。

我不想创建不同的阶段,但只想创建一个 "Documentation" 在 jenkins 视图中可见。

感谢您的建议。
普里斯科

听起来您想仅在 "${env.WORKSPACE}/firstModule/html/index.html 存在时才发布 firstModule 的文档。

而不是:

if(firstModule) {

尝试:

script {
   if (fileExists("${env.WORKSPACE}/firstModule/html/index.html")) {
     # publishHTML and whatnot
   }
}