将时间戳附加到 builspec.yaml 文件中的 S3 存储桶文件夹

Append timestamp to a S3 bucket folder in builspec.yaml file

我是 YAML 文件的新手。我想每次都将时间戳附加到 S3 存储桶文件夹,以便每个构建都是唯一的。在 post_build 中,我将时间戳附加到 S3 存储桶,如下所示。当代码管道被触发时,所有文件都存储到 S3 存储桶 Inhouse 文件夹中,但不会生成带有时间戳的文件夹。 s3://${S3_BUCKET}/Inhouse/${'date'}

Version: 0.2
env:
    variables:
        S3_BUCKET: Inhouse-market-dev
phases:
    install:
        runtime-versions:
            nodejs: 10
        commands:
            - npm install
            - npm install -g @angular/cli
    build:
        commands:
            - echo Build started on `date`
    post_build:
         commands:
            - aws s3 cp . s3://${S3_BUCKET}/Inhouse/${'date'} --recursive --acl public-read --cache-control "max-age=${CACHE_CONTROL}"
            - echo Build completed on `date`

我认为您对 ${'date'} 的使用不正确。我建议尝试以下方法来实际获取 unix 时间戳:

    post_build:
         commands:
            - current_timestamp=$(date +"%s")
            - aws s3 cp . s3://${S3_BUCKET}/Inhouse/${current_timestamp} --recursive --acl public-read --cache-control "max-age=${CACHE_CONTROL}"
            - echo Build completed on `date` which is ${current_timestamp}