title: Deploy php web application on Elastic Beanstalk using Jenkins, git and eb cli
body: <p>I have a php application that i want to deploy to an elastic beanstalk environment using Jenkins. The Code is on git and i want to be able to use eb cli commands like
  eb use 
  eb deploy.</p>
  
  <p>So, i am not sure how to make this work... as in how to set up the credentials so that i can have the eb cli commands run using the Jenkins shell.</p>
  
  <p>Any thoughts about how to go about this would be very helpful.</p>
  
  <p>My script currently looks a bit like this</p>
  
  <pre><code>git fetch
  
  git checkout "$GIT_REF"
  
  git pull origin "$GIT_REF"
  
  eb use "$CUSTOM_EB_ENV"
  
  eb deploy
  </code></pre>
  
  <p>$GIT_REF and $CUSTOM_EB_ENV are variables pointing to git branch and ElasticBeanstalk environment name.</p>
  
  <p>When I run the job, i get the following error</p>
  
  <pre><code>+ git fetch
  + git checkout master
  Previous HEAD position was 36f0456t... f
  Switched to branch 'master'
  Your branch is up-to-date with 'origin/master'.
  + git pull origin master
  From github.com:something/foo_bar
  * branch            master     -&gt; FETCH_HEAD
  Already up-to-date.
  + eb use Environment_name
  ERROR: Operation Denied. The security token included in the request is invalid.
  + eb deploy
  ERROR: This branch does not have a default environment. You must either specify an environment by typing "deploy my-env-name" or set a default environment by typing "eb use my-env-name".
  </code></pre>