1

I would like to know how to continue with a build only when a file contains specific text?

I want the build to fail if the text is incorrect, otherwise continue with build.

kumar
  • 11
  • 2
  • what does your Jenkinsfile look like so far? what have you tried? – burnettk May 03 '17 at 22:43
  • File is on a vm in which the job is configured to run. I have a shell script to check the contents. – kumar May 03 '17 at 22:58
  • Does this answer your question? [Fail Jenkins pipeline stage if some file contains specific strings](https://stackoverflow.com/questions/55301993/fail-jenkins-pipeline-stage-if-some-file-contains-specific-strings) – rüff0 Sep 28 '21 at 02:57

1 Answers1

0

update your script to return a nonzero exit status when the file doesn't contain the text. run your shell script via an sh step like this:

sh '/path/to/your/script_that_checks_another_file_for_certain_text.sh'

full pipeline:

pipeline {
  agent { label 'docker' }
  stages {
    stage('build') {
      steps {
        sh '/path/to/your/script_that_checks_another_file_for_certain_text.sh'
        echo 'this will not happen if the above script returns a bad exit status'
      }
    }
  }
}
burnettk
  • 13,557
  • 4
  • 51
  • 52