Search code examples
jenkinsjenkins-pluginsjenkins-pipeline

Can you identify from inside a Jenkins pipeline if its the first run of a new branch?


Is it possible to see if a pipeline job is the first run of a newly discovered branch from inside the pipeline itself? If you could get a list of all the runs of a job, maybe you could see if there are 0 previous runs and thereby know it's the first run?


Solution

  • Use env.BUILD_NUMBER. env.BUILD_NUMBER == '1' if this is the first build.

    For newly discovered branches in Multibranch Pipeline (which I assume you use) this will work.