amplify-hosting icon indicating copy to clipboard operation
amplify-hosting copied to clipboard

Trigger a build to deploy the latest commit

Open gargshantnu opened this issue 4 years ago • 14 comments

  1. 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.

  2. Detailed Steps To Reproduce

    1. integrate a branch and deploy it.
    2. disable Auto-Build for that branch.
    3. commit something in the branch.
    4. try "Redeploy this version", and after complete deployment check if new changes are coming.
  3. Amplify console logs under "Cloning repository"

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
  1. 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.

  2. 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 avatar Apr 17 '20 08:04 gargshantnu

@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 avatar Apr 17 '20 17:04 swaminator

@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?

gargshantnu avatar Apr 18 '20 08:04 gargshantnu

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

Screen Shot 2020-06-08 at 11 02 52 AM

Build is not free (and expensive). Please fix it ASAP Git Repo: Bitbucket

gaochenyue avatar Jun 08 '20 15:06 gaochenyue

@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.

mantsika avatar Jul 03 '20 08:07 mantsika

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

RohitChattopadhyay avatar Nov 15 '20 20:11 RohitChattopadhyay

Echoing @gaochenyue 's issue, the build history links to the incorrect place in Github because it always points to HEAD.

I've opened support case 8411000031 with our details. I am able to set --commitMessage correctly but commitId always points to HEAD even when explicitly setting it with --commit-id from the CLI. This is confusing for our developers, particularly when they're dealing with an incident and under pressure.

mwarkentin avatar Jun 03 '21 15:06 mwarkentin

Been a year or so now. any chance AWS can work out how to trigger a build - Like you use dto be able to do when things failed before you "upgraded" down to this way of doing it.

marksteven avatar Aug 25 '22 20:08 marksteven

Any news on this?

muriloloopbaby avatar Sep 27 '22 17:09 muriloloopbaby

upvote

yehonadav avatar Mar 08 '24 06:03 yehonadav

a work around is to add

   - git pull

to preBuild commands, then you can click on "redeploy this version" and it will instead deploy the latest commit, the downside is you lose the ability to deploy anything but the latest

yehonadav avatar Mar 08 '24 12:03 yehonadav

upvote, we need a button in the amplify console UI which trigger a new build when CI is turned off.

bergmorten avatar May 15 '24 07:05 bergmorten

+1

fyrkantis avatar Jun 06 '24 14:06 fyrkantis