Level-3, Jenkins "Jenkins Conditional Pipeline" - Validation Issue

Hi Team, I have done a task correctly, Still validation failed… @mmumshad @Tej-Singh-Rana @inderpreetaps Can you please help me out, I am sharing my pipeline script below.

pipeline {
agent {
label ‘ststor01’
}

parameters {
    string(name: 'BRANCH', defaultValue: 'master', description: 'parameter for branch')
}

stages {
    stage('Deploy') {
        steps {
            script {
              
              def branch = params.BRANCH
              echo "Using ${branch}"
              
              checkout scmGit(
                  branches: [[name: "*/${params.BRANCH}"]], 
                  extensions: [], 
                  userRemoteConfigs: [[credentialsId: 'git-pass', url: 'http://git.stratos.xfusioncorp.com/sarah/web_app.git']]
                  )
            }
        }
    }
}

}


Update - Completed the TASK successfully, Modified my pipeline a bit…

pipeline {
agent {
label ‘ststor01’
}

parameters {
    string(name: 'BRANCH', defaultValue: 'master', description: 'parameter for branch')
}

stages {
    stage('Deploy') {
        steps {
            script {
              
              def branch = params.BRANCH
              echo "Using ${branch}"
              
              checkout scmGit(
                  branches: [[name: "*/${params.BRANCH}"]], 
                  extensions: [], 
                  userRemoteConfigs: [[credentialsId: 'git-pass', url: 'http://git.stratos.xfusioncorp.com/sarah/web_app.git']]
                  )
              
              if (params.BRANCH == 'master') {
                    echo "Deploying master branch..."
                    sh 'rm -rf /var/www/html/*.html'
                    sh 'cp -pr /var/www/html/workspace/datacenter-webapp-job/* /var/www/html/'
                } 
                
              else if (params.BRANCH == 'feature') {
                    echo "Deploying feature branch..."
                    sh 'rm -rf /var/www/html/*.html'
                    sh 'cp -pr /var/www/html/workspace/datacenter-webapp-job/* /var/www/html/'
                } 
                
              else {
                    error "Invalid BRANCH parameter value: ${params.BRANCH}"
                }
            }
        }
    }
}

}

1 Like