使用Jenkins,git和eb cli在Elastic Beanstalk上部署php Web应用程序

使用Jenkins,git和eb cli在Elastic Beanstalk上部署php Web应用程序

问题描述:

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.

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.

Any thoughts about how to go about this would be very helpful.

My script currently looks a bit like this

git fetch

git checkout "$GIT_REF"

git pull origin "$GIT_REF"

eb use "$CUSTOM_EB_ENV"

eb deploy

$GIT_REF and $CUSTOM_EB_ENV are variables pointing to git branch and ElasticBeanstalk environment name.

When I run the job, i get the following error

+ 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     -> 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".

我有一个php应用程序,我想使用Jenkins部署到弹性beanstalk环境。 代码是在git上,我希望能够使用eb cli命令,例如 eb use eb deploy。 p>

所以,我不知道如何使这项工作... 在如何设置凭据,以便我可以使用Jenkins shell运行eb cli命令。 p>

任何有关如何进行此操作的想法都会非常有用。 p>

我的脚本目前看起来有点像这样 p>

  git fetch 
 
git checkout“$ GIT_REF”
 
git pull origin“$ GIT_REF”  
 
eb使用“$ CUSTOM_EB_ENV”
 
eb deploy 
  code>  pre> 
 
 

$ GIT_REF和$ CUSTOM_EB_ENV是指向git branch和ElasticBeanstalk环境名称的变量。 p >

当我运行作业时,我收到以下错误 p>

  + git fetch 
 + git checkout master 
以前的HEAD位置是36f0456t ...  f 
切换到分支'master'
你的分支是最新的'origin / master'。
 + git pull origin master 
来自github.com:something / foo_bar
* branch master  - >  FETCH_HEAD 
已经是最新的。
 + eb使用Environment_name 
ERROR:操作被拒绝。 请求中包含的安全令牌无效。
 + eb deploy 
ERROR:此分支没有默认环境。 您必须通过键入“deploy my-env-name”来指定环境,或者通过键入“eb use my-env-name”来设置默认环境。
  code>  pre> 
  div>

In order to use the EB CLI in a directory you first have to run eb init but it looks like you have already done that.

The problem you are having seems to be from the lack of valid credentials. The EB CLI pulls credentials the same way the AWS CLI does, you can find more information in the documentation.

You will most likely have to setup a pair of AWS credentials for your jenkins server. One way to do this would be to created the file $JENKINS_HOME/.aws/credentials and store your AWS credentials in there.

[default]
aws_access_key_id = MYAWSACCESSKEY
aws_secret_access_key = MYAWSSECRETKEY

With that file created the EB CLI will automatically pull the credentials and run the desired operations.