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

半城伤御伤魂 提交于 2020-04-16 02:38:07

问题


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 its the first run?


回答1:


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.




回答2:


In case you mean to identify the build number from within the Jenkins pipeline, then yes, it can be identified using the pipeline Global Variable currentBuild. This variable may be used to discover information about the currently executing pipeline, with properties such as currentBuild.result, currentBuild.displayName, etc. You may use the property currentBuild.id to know the build number and hence whether it is the first build or not.

You may consult the built-in Global Variable Reference at the URL http://[your-Jenkins-host]/pipeline-syntax/globals#currentBuildfor for a complete and up-to-date list of properties available on currentBuild.

Hope, it helps.



来源:https://stackoverflow.com/questions/54151175/can-you-identify-from-inside-a-jenkins-pipeline-if-its-the-first-run-of-a-new-br

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!