Issue Description
When I am clicking on "Redeploy this version", after cloning the repository, amplify is doing git checkout to an old commit, which I think is of the time when I connected the branch.
Detailed Steps To Reproduce
2020-04-16T15:26:39.797Z [INFO]: Git SSH Key acquired
2020-04-16T15:26:39.863Z [INFO]: # Cloning repository: SENSITIVE_DATA
2020-04-16T15:26:39.991Z [INFO]: Agent pid 117
2020-04-16T15:26:39.995Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
2020-04-16T15:26:40.245Z [INFO]: Cloning into SENSITIVE_DATA
2020-04-16T15:26:40.520Z [INFO]: Warning: Permanently added the RSA host key for IP address SENSITIVE_DATA to the list of known hosts.
2020-04-16T15:26:49.307Z [INFO]: # Switching to commit: COMMIT_ID
2020-04-16T15:26:49.652Z [INFO]: Note: checking out 'COMMIT_ID'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at SENSITIVE_DATA Merge pull request SENSITIVE_DATA from SENSITIVE_DATA
2020-04-16T15:26:49.653Z [INFO]: # Checking for Git submodules at: /codebuild/output/src076219606/src/FOLDER_NAME/.gitmodules
2020-04-16T15:26:49.675Z [INFO]: # Retrieving cache...
2020-04-16T15:26:55.960Z [INFO]: # Extracting cache...
2020-04-16T15:27:02.145Z [INFO]: # Extraction completed
2020-04-16T15:27:02.501Z [INFO]: # Retrieving environment cache...
2020-04-16T15:27:02.546Z [INFO]: # Retrieved environment cache
Expected behavior
Each time I click on "Redeploy this version", the respective branch should be fetched from GitHub and it should be deployed with new changes, i.e. there must not be any checkout until unless I mention in the build settings.
Application Details
a. Amplify Console AppID: d392v2bx7rclk2
__If the issue is related to a build, please also share:__
b. The specific Branch and Build number we should investigate
branch name: release-6.4
build number: 4
c. Your build spec
version: 1.0
frontend:
phases:
preBuild:
commands:
- cd react
- npm i
build:
commands:
- if [ "${ENV_V1}" = "x1" ] && [ "${ENV_V2}" = "y1" ]; then npm run build-test-km; fi
- if [ "${ENV_V1}" = "x2" ] && [ "${ENV_V2}" = "y1" ]; then npm run build-staging-km; fi
- if [ "${ENV_V1}" = "x1" ] && [ "${ENV_V2}" = "y2" ]; then npm run build-test-al; fi
- if [ "${ENV_V1}" = "x2" ] && [ "${ENV_V2}" = "y2" ]; then npm run build-staging-al; fi
- if [ "${ENV_V1}" = "x3" ] && [ "${ENV_V2}" = "y1" ]; then npm run build-prod-km; fi
- if [ "${ENV_V1}" = "x3" ] && [ "${ENV_V2}" = "y2" ]; then npm run build-prod-al; fi
# If no environment variable is provided then build kommunicate test bundle.
- if [ "${ENV_V1}" = "" ] || [ "${ENV_V2}" = "" ]; then npm run build-test-km; fi
artifacts:
# build output directory
baseDirectory: react/build
files:
- '**/*'
cache:
paths:
- react/node_modules/**/*
# - react/package-lock.json
customHeaders:
- pattern: '**/*'
headers:
- key: 'Cache-Control'
# 15 day
value: 'public, must-revalidate, max-age=1296000'
# dont cache index.html
- pattern: '**/*.html'
headers:
- key: 'Cache-Control'
value: 'no-cache, no-store, must-revalidate'
@gargshantnu currently there isn't a way to trigger to the latest commit (it's in our backlog and we'll get to it pretty soon). Workaround for now is to re-enable autobuild and do a commit.
@swaminator for a workaround, can we do
preBuild:
- <OTHER_COMMANDS>
- git checkout $AWS_BRANCH
- git pull
since Github is initialized in the folder, and RSA host key for IP address is also added, as seen from logs.
Can this work? Also, when can we expect the feature release for the same?
When we deploy with AWS cli below, it does use the latest commit, but the commit ID always refers to HEAD while we know that each build uses different commit for sure. So it makes the build history useless. We can't know which commit each build was created from. Also no matter which git branch the build is on, the HEAD link always points to "https://bitbucket.org/project/branch/commits/HEAD", which is the master HEAD by default
aws amplify start-job --app-id <appid> --branch-name <branchname> --job-type RELEASE

Build is not free (and expensive). Please fix it ASAP
Git Repo: Bitbucket
@swaminator can we just confirm that the expected behaviour is that each amplify build is based on commitID, which will always create detached HEAD? (we use github). From the log:
2020-04-16T15:26:49.307Z [INFO]: # Switching to commit: COMMIT_ID
2020-04-16T15:26:49.652Z [INFO]: Note: checking out 'COMMIT_ID'.
You are in 'detached HEAD' state.
If we always create a detached HEAD, then it seems the behaviour of the 'redeploy this version ' is correct. And we can ignore what seems like an error message.
As a way around You can trigger builds using webhooks, the build uses the HEAD commit.
https://docs.aws.amazon.com/amplify/latest/userguide/webhooks.html
Most helpful comment
When we deploy with AWS cli below, it does use the latest commit, but the commit ID always refers to HEAD while we know that each build uses different commit for sure. So it makes the build history useless. We can't know which commit each build was created from. Also no matter which git branch the build is on, the HEAD link always points to "https://bitbucket.org/project/branch/commits/HEAD", which is the master HEAD by default
aws amplify start-job --app-id <appid> --branch-name <branchname> --job-type RELEASEBuild is not free (and expensive). Please fix it ASAP
Git Repo: Bitbucket