使用Bitbucket AWS CodeDeploy插件进行部署时生成“.env”

时间:2018-05-07 05:49:12

标签: bitbucket aws-code-deploy bitbucket-pipelines bitbucket-aws-code-deploy

使用Bitbucket AWS CodeDeploy插件进行部署时如何生成“.env”?

我看到bitbucket-pipelines.yml可以从bitbucket环境变量生成.env,但是,如何将它与Bitbucket AWS CodeDeploy插件联系起来?

appspec.yml - 可以在部署时触发脚本但是如何从bitbucket环境变量中获取.env?

2 个答案:

答案 0 :(得分:0)

查看documentation,BitBucket应该在构建环境中使环境可用,并且您应该能够直接在appspec.yml运行的脚本中访问它们,就像访问任何其他环境一样环境变量。

例如,如果我们有这样的appspec:

hooks:
   AfterInstall:
     - location: scripts/runTests.sh
       timeout: 180

您可以像scripts/runTests.sh一样访问# scripts/runTests.sh echo "$BITBUCKET_BUILD_NUMBER" # Or, use in some other valid way in your script 中的环境变量:

function generate_hello(element) {
    var template = jQuery('#hello_template');
    return mustache(template.html(), {
        tooltip: 'Hello'
    });
    ..nothing gets executed here, no selecting in jQuery, no nothing.
}

答案 1 :(得分:0)

BitBucket不应创建.env,该服务应该对生产.env一无所知。相反,生产.env应该坐在安全的AWS S3 bucket上,那里只有AWS CodeDeploy脚本可以接受它并将其放在实例上。

它会像这样被复制

sudo aws --region us-east-2 s3 cp "s3://${S3_NAME}/prod.env" "${EC2_DIRECTORY}/.env"
相关问题