1

I've created a code pipeline for the PHP laravel base project with bitbucket. Passing parameter using AWS SSM to the appspec.yml All are working fine with the development branch. I need to update the parameters from the AWS SSM based on the branch name on appspec.yml file.

FOR DEV

Branch name: develop
parameter value: BRANCH_NAME_VALUE (develop_value)

FOR QA

Branch name: qa
parameter value: BRANCH_NAME_VALUE(qa_value)

appspec.yaml file

version: 0.0
os: linux
files:
  - source: /
    destination: /var/www/html/
    overwrite: true
hooks:
  BeforeInstall:
    - location: scripts/before_install.sh
      timeout: 300
      runas: root
  AfterInstall:
    - location: scripts/after_install.sh
      timeout: 300
      runas: root

How I can get the BRANCH_NAME for update the after_install.sh

Marcin
  • 215,873
  • 14
  • 235
  • 294
bibincatchme
  • 333
  • 4
  • 10

2 Answers2

0

Not sure what do you want to do, but you can't pass arbitrary env variables to CodeDeploy. The only supported ones are:

LIFECYCLE_EVENT : This variable contains the name of the lifecycle event associated with the script.
DEPLOYMENT_ID :  This variables contains the deployment ID of the current deployment.
APPLICATION_NAME :  This variable contains the name of the application being deployed. This is the name the user sets in the console or AWS CLI.
DEPLOYMENT_GROUP_NAME :  This variable contains the name of the deployment group. A deployment group is a set of instances associated with an application that you target for a deployment.
DEPLOYMENT_GROUP_ID : This variable contains the ID of the deployment group in AWS CodeDeploy that corresponds to the current deployment

Thus, in your case you could have two development groups called develop and qa. Then, in the CodeDeploy scripts you could test the branch name using
DEPLOYMENT_GROUP_NAME and get respective SSM parameters.

Marcin
  • 215,873
  • 14
  • 235
  • 294
0

Seems that you are trying to merge branches, and are facing issues where specific files or directories change per branch. I faced similar issue, and we can try to create .gitattributes per branch. The destination branch will have this so that once it is merged the specific files in the source branch wont overwrite the destination branch.

Check Reference:-

  • List item

https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_merge_strategies

  • List item

Git - Ignore files during merge

Example:-

2 branches master (For Production Environment) and Stage (For Development Environment)

git config --global merge.ours.driver true
git checkout master
echo "appspec.yml merge=ours" >> .gitattributes
echo "scripts/before-install.sh merge=ours" >> .gitattributes
git merge stage

$ cat .gitattributes
appspec.yml merge=ours
scripts/before-install.sh merge=ours

Summary:- so the idea is to keep the appspec.yml clean and environment free and handle it at git level itself. Unfortunately appspec.yml does not still support variables to accommodate per Branch. Additionally, I would also add the above paths to .gitignore per branch to avoid them being altered during commits. Above is just a example, in production setup you could by default disable commits to master branch and only use pull requests with manual approval at AWS CodePipeline level with SNS topics for approval emails. And use a feature branch and merge to Stage first.

PRANAV D
  • 1
  • 1