我正在尝试创建一个Circleci工作流,该工作流将Java WAR构建并上传到我的组织现有的S3工件存储桶存储库中。首先,构建项目,并将一些信息保存在文件中,然后将VERSION放入BASH_ENV:
export "VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $BASH_ENV
if [ $CIRCLE_BRANCH = "master" ]; then
ENVIRONMENT=production
elif [ $CIRCLE_BRANCH = "develop" ]; then
ENVIRONMENT=qa
elif [ $CIRCLE_BRANCH = "release-1.0" ]; then
ENVIRONMENT=staging
else
ENVIRONMENT=$CIRCLE_BRANCH
fi
echo "ENVIRONMENT=$ENVIRONMENT" >> project.info
if [ -z "$ENVIRONMENT" ]; then
echo No environment is set
exit 1
fi
然后,我尝试使用官方的S3 Orb上传工件:
steps:
- attach_workspace:
at: .
- run: source project.info
- run: export "VERSION=$VERSION" >> $BASH_ENV
- aws-s3/copy:
from: target/project-${VERSION}.war
to: 's3://artifact.bucket/project/project-${VERSION}.war'
arguments: '--dryrun'
此上传任务失败,并显示The user-provided path target/project-.war does not exist.
,因为正在插入一个空字符串而不是预期的版本。
Circleci文档指出:
在每个步骤中,CircleCI都使用bash来获取BASH_ENV。这意味着BASH_ENV将自动加载并运行,从而允许您使用插值并在运行步骤之间共享环境变量。
但是似乎并非如此。如何使S3上传任务使用我设置的环境变量?