Prisco
Prisco

Reputation: 733

Jenkinsfile conditions in Stage phase

should it possible to define several conditions in a Stage phase of Jenkins file??
Let me to explain my problem: I want to publishHtml in my Jenkins pipeline only if a condition is valid:

        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"
            ])
         }
     }

I don't know if firstModule was built or not... this is what I would like to know.

I don't want to create different stages, but just one "Documentation" visible in the jenkins view.

Thank for your suggestion.
Prisco

Upvotes: 2

Views: 588

Answers (1)

burnettk
burnettk

Reputation: 14037

it sounds like you want to publish documentation for firstModule only if "${env.WORKSPACE}/firstModule/html/index.html exists.

instead of:

if(firstModule) {

try:

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

Upvotes: 1

Related Questions