2
votes

I have a node.js on gitlab repo and I am trying to push it into AWS EC2 Ubntu server using CI pipeline.

I am trying to implement a CI pipeline between my gitlab repo and the EC2 instance in a way that every time I push a new code the pipeline gets triggered and the code goes to EC2 server automatically.

I have added environment with name and the url to yaml file. (the url is the AWS server address with git installed on it)

My current .gitlab-ci.yml file looks like below:

image: node:6.10.3

stages:
  - ver
  - init
  - tests
  - deploy

ver:
  stage: ver
  script:
    - node --version
    - whoami
init:
  stage: init
  script:
    - npm cache clean
    - rm -rf node-modules
    - npm install
run_tests:
  stage: tests
  before_script: 
    - chmod 0777 ./node_modules/.bin/_mocha
  script:
    - npm test

deploy_staging:
  stage: deploy
  script:
    - echo "Going to deploy to staging server"
  environment:
    name: staging
    url: http://EC2DNS_Address.amazonaws.com/test/ci-test

  only:
    - master

when I commit a new changes I can see the pipeline gets triggers but I don't see any changes applied to the server.

How can I push these changes into my ubuntu server? do I need something more than the environment tag?

2

2 Answers

3
votes

Yes. You also need to implement the actual deploy by using script tags. I'm afraid there is no magical way this will happen.

So either use SCP or SSH commands or whatever you use to deploy your application to the server you specify in environment.

As the Gitlab docs explain:

Environments are like tags for your CI jobs, describing where code gets deployed. Deployments are created when jobs deploy versions of code to environments, so every environment can have one or more deployments.

1
votes

Check status of deploy stage to find the problem.

to deploy on AWS set sensitive variables (name, access keys) in the Project Setting (in the Gitlab) and use them in your gitlab-ci.yml

I think this link is for you.