How to deploy web application to AWS instance from GitLab repository

You need to create a .gitlab-ci.yml file in your repository with CI jobs defined to do the two tasks you've defined.

Here's an example to get you started.

stages:
  - build
  - deploy

build:
  stage: build
  image: gradle:jdk
  script:
    - gradle build
  artifacts:
    paths:
      - my_app.jar

deploy:
  stage: deploy
  image: ubuntu:latest
  script:
    - apt-get update
    - apt-get -y install openssh-client
    - scp my_app.jar target.server:/my_app.jar

In this example, the build job run a gradle container and uses gradle to build the app. GitLab CI artifacts are used to capture the built jar (my_app.jar), which will be passed on to the deploy job.

The deploy job runs an ubuntu container, installs openssh-client (for scp), then executes scp to open my_app.jar (passed from the build job) to the target server.

You have to fill in the actual details of building and copying your app. For secrets like SSH keys, set project level CI/CD variables that will be passed in to your CI jobs.