I have a Jenkinsfile having a path in this order (assuming Green envs are binded to production only):
Build-->Deploy-to-QA-->Deploy-To-Preprod-->Deploy-To-BLUE-Production-->Bind to Blue envs to Load Balancer--> Unbind Green Env-->Deploy to Green--> Bind Green--> Unbind Blue
This order seems to be good if we are being too optimistic,because in some cases, there might be a problem with green env, and admin user can bind the blue envs manually, or both can be binded together to the production.
Therefore, I have written a script which makes an API call to the LB and gets the binded service group.
But I could not figure out how to redirect the pipeline by getting the result of api.
If endpoint returns blue is binded, it should start deploying from green, if endpoint returns green is binded info, it should start deploying from blue env in my case.
But as far as I see, I cannot wrap the stages within a function in Jenkinsfile.