To define a default value when BITRISE_BUILD_NUMBER is not available, you can do something like this: Intermittent build failures to execute push_to_git_remote & how to manage build number
def bitriseBuildNumber = System.getenv("BITRISE_BUILD_NUMBER")
def buildNumber = bitriseBuildNumber != null ? bitriseBuildNumber : "0"