jeudi 28 février 2019

Jenkins Pipeline - if statement always returns false

I currently have a problem. I am working with openshift and am trying to use an if statement depending on wether an Integration Test in a seperate container succeeded. This this is a snippet of my code

podTemplate(....

){
  node(myLabel){
    container('jnlp'){
      ...
      stage(Integration Tests){
        ...
         script{
          def status = sh(script: 'oc describe pod myapps-integration-tests | grep -i status: | awk {\'print $2\'}', returnStdout: true)
          echo "Status of Interation Test Job ${status}"
          echo status
          if("${status}" == "Succeeded"){             
            echo "Integration tests successfull"  
          } else {              
            echo "Integration Tests failed"
            error("The integration tests failed.")              
          }
        }
        ...
}

Now the problem is, that this if statement always always returns false. status echoes as Succeeded but still the statement returns false. I've tried with and without the script block. I tried

if(status == "Succeeded")

but still. It always tells me my integraion test failed. If i replace the statement with "Succeeded" == "Succeeded" just for testing it passes as expected. Does anyone have an idea what I am doing wrong?

Aucun commentaire:

Enregistrer un commentaire