【问题标题】:Jenkinsfile conditions in Stage phase阶段阶段的 Jenkinsfile 条件
【发布时间】:2017-05-12 17:48:05
【问题描述】:

是否可以在 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 是否已构建...这是我想知道的。

我不想创建不同的阶段,而只想创建一个在 jenkins 视图中可见的“文档”。

感谢您的建议。
普里斯科

【问题讨论】:

    标签: bash jenkins conditional jenkins-pipeline


    【解决方案1】:

    听起来您只想在 "${env.WORKSPACE}/firstModule/html/index.html 存在的情况下发布 firstModule 的文档。

    代替:

    if(firstModule) {
    

    尝试:

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

    【讨论】:

      最近更新 更多