我正在创建一个Bitbucket管道,用于将代码从Bitbucket部署到AWS EC2实例。在管道中这样做所需的步骤是:
将ZIP文件部署到EC2实例
我希望在将zip文件上传到S3桶时调用它。为此,我使用$BITBUCKET_REPO_SLUG管道变量并设置管道的第一步,如下所示,其中applications是我想要打包到zip文件中的存储库中的文件夹。
staging:
- step:
name: Zip Code
image: atlassian/default-image:3
script:
- zip -r "$BITBUCKET_REPO_SLUG.zip" "applications"
artifacts:
- "$BITBUCKET_REPO_SLUG.zip"但是,从下面的管道输出(在Build下)可以看到,$BITBUCKET_REPO_SLUG.zip并没有像预期的那样更改为<repository_name>.zip。
zip -r "$BITBUCKET_REPO_SLUG.zip" "applications"
+ zip -r "$BITBUCKET_REPO_SLUG.zip" "applications"
adding: applications/ (stored 0%)
adding: applications/configuration/ (stored 0%)
adding: applications/configuration/trade_capture_trayport_private.ini (deflated 58%)
adding: applications/trade_capture_etrm/ (stored 0%)
adding: applications/trade_capture_etrm/trade_capture_trayport_private.ps1 (deflated 73%)
adding: applications/trade_capture_etrm/etrm_private_alerting.ps1 (deflated 65%)
adding: applications/trade_capture_etrm/tests/ (stored 0%)
adding: applications/trade_capture_etrm/tests/trayport.tests.ps1 (deflated 93%)
adding: applications/appspec.yml (deflated 70%)
Build teardown
Searching for files matching artifact pattern $BITBUCKET_REPO_SLUG.zip
Searching for test report files in directories named [test-results, failsafe-reports, test-reports, TestResults, surefire-reports] down to a depth of 4
Finished scanning for test reports. Found 0 test report files.
Merged test suites, total number tests is 0, with 0 failures and 0 errors.在接下来的步骤中,当上传到S3时,我使用相同的方法来引用zip文件,如下面的代码所示
- step:
name: ⬆️ Upload to S3
services:
- docker
oidc: true
script:
# Test upload
- pipe: atlassian/aws-code-deploy:1.1.1
variables:
AWS_DEFAULT_REGION: $AWS_REGION
AWS_OIDC_ROLE_ARN: $AWS_OIDC_ROLE_ARN
COMMAND: 'upload'
APPLICATION_NAME: $APPLICATION_NAME
ZIP_FILE: "$BITBUCKET_REPO_SLUG.zip"
S3_BUCKET: $S3_BUCKET_STAGING
VERSION_LABEL: $BITBUCKET_REPO_SLUG从上传到S3步骤的输出可以看出,$BITBUCKET_REPO_SLUG.zip被正确地转换为.zip
INFO: Authenticating with a OpenID Connect (OIDC) Web Identity Provider
INFO: Executing the aws-ecr-push-image pipe...
INFO: Uploading powershell_trade_capture.zip to S3.
Traceback (most recent call last):
File "/pipe.py", line 264, in <module>
pipe.run()
File "/pipe.py", line 254, in run
self.upload_to_s3()
File "/pipe.py", line 230, in upload_to_s3
with open(self.get_variable('ZIP_FILE'), 'rb') as zip_file:
FileNotFoundError: [Errno 2] No such file or directory: 'powershell_trade_capture.zip'为什么管道变量$BITBUCKET_REPO_SLUG被正确地转换为“上载到S3”步骤中的值,而没有在"Zip代码“步骤中转换为存储库名称(而不是作为字符串)?
发布于 2022-05-12 22:05:26
问题是,Bitbucket管道的工件部分目前不支持变量替换。有关2022年2月创建的详细信息,请参见https://jira.atlassian.com/browse/BCLOUD-21666。
我们找到的解决方案是解决问题,避免使用工件部分。我们通过将"Zip“和”上载到管道的S3“部分结合起来来做到这一点。这意味着不再需要使用人工制品。
因此,这个新的部分设置如下。
- step:
name: ⬆️ Zip & Upload to S3
services:
- docker
oidc: true
image: atlassian/default-image:3
script:
# Build the zip file
- zip -r $BITBUCKET_REPO_SLUG.zip "applications"
# Upload the zip file to S3
- pipe: atlassian/aws-code-deploy:1.1.1
variables:
AWS_DEFAULT_REGION: $AWS_REGION
AWS_OIDC_ROLE_ARN: $AWS_OIDC_ROLE_ARN
COMMAND: "upload"
APPLICATION_NAME: $APPLICATION_NAME
ZIP_FILE: $BITBUCKET_REPO_SLUG.zip
S3_BUCKET: $S3_BUCKET_STAGING
VERSION_LABEL: $BITBUCKET_REPO_SLUG在这种情况下,$BITBUCKET_REPO_SLUG的使用没有问题,管道也成功了。
发布于 2022-05-12 07:59:42
您不需要zip或工件的引号,因此我假设它没有正确地转换变量。
https://stackoverflow.com/questions/72208433
复制相似问题