Multistage pipeline failure

My jenkins pipeline failed with the Test Stage please see my code and screenshots:
Please see the below code:

def tes = false
pipeline {
agent { label ‘ststor01’ }
stages
{
stage(‘Deploy’) {
steps {
script{
try {
sh ‘echo Bl@kW | sudo -S cp /home/sarah/web/* /data/’
sh ‘echo ${tes}’
tes=true
}
catch(Exception e){
tes=false
}
}
}
post {
success {
echo ‘success!’
}
}
}
stage(‘Test’) {
steps {
script {
if(tes) {
sh ‘curl http://stlb01:80
sh ‘echo Deployment Success’
}
else {
sh ‘echo Deployment failed’
sh ‘exit 1’
}
}
}
}
}
}

I have commented on your review as well. The problem is with your Test stage. It needs to be designed in such a way that it fails when the deployment is incorrect. So it should be more than a simple curl.

For example, it can be

stage(‘Test’) {
  steps {
    script {
      sh '((curl http://stapp01:8080/ | grep -F "Welcome to xFusionCorp Industries") && true)'
    }
  }
}

Above will return with a non-zero exit code if the content returned by curl is not Welcome to xFusionCorp Industries causing your Test stage to fail

Hi,

thanks a lot for suggestion, I will go ahead and try this out to see if this works. my one doubt is if there should be a poll scm: * * * * * or should I configure the git scm code via code in the pipeline script?

Hi,
I failed this task again I followed your pipeline code, as it is but I knew what it is was checking. This time again I dont know what happend? Please help.

def remote = [:]
remote.name = ‘ststor01’
remote.host = ‘ststor01’
remote.user = ‘natasha’
remote.password = ‘Bl@kW’
remote.allowAnyHosts = true

pipeline {
// Run on agent with label ‘ststor01’
agent { label ‘ststor01’ }

// Pipeline stages 
stages {
    // Deploy stage
    stage('Deploy') {
        steps {
            echo 'Deploying ...'
            // Connect to GIT and download the repo code
            // Use the Jenkins Credentials by ID: GIT_CREDS
            git credentialsId: 'GIT_CREDS', url: 'http://git.stratos.xfusioncorp.com/sarah/web.git'
            // Transfer all the files we downloaded to /tmp of ststor01
            sshPut remote: remote, from: '.', into: '/tmp'
            // Finally move all the files from /tmp to /data on ststor01
            sshCommand remote: remote, command: "mv -f /tmp/${JOB_NAME}/* /data"
        }
    }

    // Test stage
    stage('Test') {
        environment {
            // Store the index.html content we received from GIT in a variable
            INDEX_CONTENT = sh(script: 'cat index.html', , returnStdout: true).trim()
        }
       
        steps {
            sh 'echo "Content from GIT: $INDEX_CONTENT"'
            // Now test that the content from default page from HTTPD on each 
            // of the appservers is same as the index.html content from GIT
            sh '((curl http://stapp01:8080/ | grep -F "$INDEX_CONTENT") && true)'
            sh '((curl http://stapp02:8080/ | grep -F "$INDEX_CONTENT") && true)'
            sh '((curl http://stapp03:8080/ | grep -F "$INDEX_CONTENT") && true)'
        }
    }
}

}