git and jenkins integration


I am looking for an example like below, how to resolve it. Could you guide me please? Or add a video here with instructions?



I have a ruby script which does the following three scenarios and loops in & out based on its findings.
A) if the source code version is same in both environments, chef do nothing. 
B) if the source code version same (1.1.0) chef version not matched (but exists) (1.1.1,1.1.0) ,check current  version and older versions and do nothing. 
C) if the source code versions both are mismatch then chef (ruby script) do the update to which ever version is current. 

Phase2: (how can I accomplish below phase2??) – please respond ASAP. 

need to come up with a new build job from Jenkins, so it starts integrating with the ruby script above in following steps:

  1. Build a new jenkins job and that job will trigger the above ruby script and the script again will parse the env.json variables (dev);  How can I accomplish this??
  2. For parsing environment variable, I need to make the env.json file available for Jenkins; How can I accomplish this??
  3. #1 and #2 should be tied to the release branch in Git. How can I accomplish this?
  4. When do I want to run Jenkins build job, automatically? when there is a merge request to release branch in git (after #3 is complete).  How can I accomplish this?