Hello,
I am trying to setup a bitbucket pipeline to deploy a simlple zip artifact to an EC2 instance via Codedeploy. I am using the following article published by Atlassian: https://confluence.atlassian.com/bitbucket/deploy-to-amazon-aws-875304040.html.
The pipeline succeeds till uploading to S3 and then fails when doing the deploy with this error:
Status: Downloaded newer image for bitbucketpipelines/aws-code-deploy:0.2.3
INFO: Deploying app from revision.
aws deploy get-application-revision --application-name SampleCodeDeployPega --revision revisionType=S3,s3Location={bucket=SampleCodeDeployPega-codedeploy-deployment,bundleType=zip,key=SampleCodeDeployPega-13-e912d59c}
An error occurred (RevisionDoesNotExistException) when calling the GetApplicationRevision operation: No application revision found for revision.
✖ Failed to fetch revision.
I have all the proper IAM roles assigned to the user (AmazonS3FullAccess and AWSCodeDeployFullAccess) and I am using the correct access key and credentials.
I followed the steps in the article and below are the files:
bitbucket-pipeline.yml
image: atlassian/default-image:2
pipelines:
default:
- step:
name: Build
script:
- echo "Deploying to test environment"
artifacts:
- myapp.zip
- step:
name: Upload to S3
script:
# Test upload
- pipe: atlassian/aws-code-deploy:0.2.6
variables:
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}
COMMAND: 'upload'
APPLICATION_NAME: ${APPLICATION_NAME}
S3_BUCKET: ${S3_BUCKET}
ZIP_FILE: 'myapp.zip'
- step:
name: Deploy with CodeDeploy
script:
# Test upload
- pipe: atlassian/aws-code-deploy:0.2.6
variables:
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}
COMMAND: 'deploy'
APPLICATION_NAME: ${APPLICATION_NAME}
DEPLOYMENT_GROUP: ${DEPLOYMENT_GROUP}
VERSION_LABEL: 'my-app-1.0.0'
IGNORE_APPLICATION_STOP_FAILURES: 'true'
FILE_EXISTS_BEHAVIOR: 'OVERWRITE'
WAIT: 'true'
appspec.yml:
version: 0.0
os: linux
files:
- source: myapp.zip
destination: /opt/pega/staging
hooks:
BeforeInstall:
- location: scripts/import.sh
timeout: 300
runas: pguser
This is my directory structure in bitbucket repository:
All help, hints, suggestions welcome. Thank you for helping out.
If anyone is looking for an answer to a similar question, here you go:
I needed to specify the "S3_BUCKET: ${S3_BUCKET}" variable in both the upload and deploy steps.
Once I did that, the deployment suceeded.
Hi Hitendra verma,
I am also facing the same issue , but i mentioned s3 bucket variable even the deployment has failed.
image: node:10.15.0
pipelines:
default:
- step:
name: Build
script:
- apt-get update -y
- cd admin/front-end/
- npm install
- CI=false
- npm run build
- apt-get install -y zip
- zip -r myapp.zip *
artifacts:
- admin/front-end/myapp.zip
- step:
name: Upload to S3
script:
- pipe: atlassian/aws-code-deploy:0.2.3
variables:
AWS_DEFAULT_REGION: 'us-east-1'
AWS_ACCESS_KEY_ID: 'AKIAXWJT4X2UTL2URGQJ'
AWS_SECRET_ACCESS_KEY: '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'
COMMAND: 'upload'
APPLICATION_NAME: 'codedeployapplication'
ZIP_FILE: 'admin/front-end/myapp.zip'
S3_BUCKET: 'codedeployrole'
VERSION_LABEL: 'my-app-1.0.0'
- step:
name: Deploy with CodeDeploy
services:
- docker
script:
- pipe: atlassian/aws-code-deploy:0.2.6
variables:
AWS_DEFAULT_REGION: 'us-east-1'
AWS_ACCESS_KEY_ID: 'AKIAXWJT4X2UTL2URGQJ'
AWS_SECRET_ACCESS_KEY: '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'
COMMAND: 'deploy'
APPLICATION_NAME: 'codedeployapplication'
DEPLOYMENT_GROUP: 'DG1'
VERSION_LABEL: 'my-app-1.0.0'
IGNORE_APPLICATION_STOP_FAILURES: 'true'
FILE_EXISTS_BEHAVIOR: 'OVERWRITE'
S3_BUCKET: 'codedeployrole'
WAIT: 'true'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
First, please don't share your access_key and access_key_id in public. It is not secure and leaves your account vulnerable.
second, you are using two different versions of the code-deploy pipeline in your code: 0.2.3 and 0.2.6. Please make the version consistent in your build yaml and run the pipeline again.
If it fails again, please post the full log from the "upload" and "deploy" steps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hitendra,
Thanks for your reply As per your suggestions I have maintained the same version of pipe even also i am facing the same error Please check I have attached my logs as per your requirement.
Bitbucket codes:-
image: node:10.15.0
pipelines:
default:
- step:
name: Build
script:
- apt-get update -y
- cd admin/front-end/
- npm install
- CI=false
- npm run build
- apt-get install -y zip
- zip -r myapp.zip *
artifacts:
- admin/front-end/myapp.zip
- step:
name: Upload to S3
script:
- pipe: atlassian/aws-code-deploy:0.2.3
variables:
AWS_DEFAULT_REGION: 'us-east-1'
AWS_ACCESS_KEY_ID: '=============='
AWS_SECRET_ACCESS_KEY: '==============I'
COMMAND: 'upload'
APPLICATION_NAME: 'codedeployapplication'
ZIP_FILE: 'admin/front-end/myapp.zip'
S3_BUCKET: 'codedeploys3bucket09'
VERSION_LABEL: 'my-app-1.0.0'
- step:
name: Deploy with CodeDeploy
services:
- docker
script:
- pipe: atlassian/aws-code-deploy:0.2.3
variables:
AWS_DEFAULT_REGION: 'us-east-1'
AWS_ACCESS_KEY_ID: '=============='
AWS_SECRET_ACCESS_KEY: '====================='
COMMAND: 'deploy'
APPLICATION_NAME: 'codedeployapplication'
DEPLOYMENT_GROUP: 'DG2'
WAIT: 'true'
S3_BUCKET: 'codedeploys3bucket09'
VERSION_LABEL: 'my-app-1.0.0'
IGNORE_APPLICATION_STOP_FAILURES: 'true'
FILE_EXISTS_BEHAVIOR: 'OVERWRITE'
Please find the atatched logs :-
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
from your screenshots, all steps look correct and the application revision and s3 bucket name all match.
at this point you need to check your application setup in codedeploy and make sure that codedeploy is able to deploy to the EC2 instance that you have selected as a target. Try checking the IAM role, instance tag, and permissions to allow codedeploy to access the EC2 instances you need.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hitendra,
Yes I have checked the I AM role and I have allowed them s3 full permission and code deploy role full permission to that role attached to EC2 and code deploy agent installed.
and I communicated with AWS team they are telling ur appspec. Yml file is not zipped to the s3.
When appspec. Yml file uploads to s3 while zipping maybe it will get successful.
Here I how modify my codes to zip the appspec. Yml file can you please help?
Regards,
Venkat
9052325074
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
So what I am doing is that my zip file contains the appspec.yml already. I have a step in the build section which zips up all the files in the app folder including the appspec.yml file.
Here is what the steps look like in bitbucket yml file:
- step:
name: Build
script:
- cd app && zip -r ../myapp.zip *
artifacts:
- myapp.zip
In the "app" folder I have my application code. some scripts and the appspec.yml file.
Try it, that should work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
did anyone resolve this issue, cause recently I am facing this issue, it was all good for more than a year and since yesterday I am facing this issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.