Run deploy automatically when branch receives MR on Gitlab

Viewed 39

I want to run automatically my deploy job on Gitlab when my branch receives a merge by merge request. How can I do this?

deploy-tests:
  tags:
    - aws-sdk
  stage: deploy
  only:
    - stage
  cache: {}
  script:
    - cd ngapp
    - call npm ci
    - call npm run-script i18n
    - call npm run-script lint
    - call build.bat tests
    - copy .htaccess dist
    - copy Web.config dist
    - deploy.bat tests
1 Answers

If you want your pipeline to be executed when it receives an MR. You need to pass the keyword merge_requests at your only clause. (https://docs.gitlab.com/ee/ci/yaml/#onlyrefs--exceptrefs) Change

deploy-tests:
  tags:
    - aws-sdk
  stage: deploy
  only:
    - stage
  cache: {}
  script:
    - cd ngapp
    ...

To

deploy-tests:
  tags:
    - aws-sdk
  stage: deploy
  only:
    - merge_requests
    - stage
  cache: {}
  script:
    - cd ngapp
    ...
Related