Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only run integration test when deploying from staging to production

I have 3 main branches in my gitlab project: dev , staging, production. I'm using postman newman for integration testing like this in .gitlab-ci.yml:

postman_tests:
    stage: postman_tests
    image: 
        name: postman/newman_alpine33
        entrypoint: [""] 
    only:
      - merge_requests
    script:
        - newman --version
        - newman run https://api.getpostman.com/collections/zzz?apikey=zzz  --environment https://api.getpostman.com/environments/xxx?apikey=xxxx

this script only run in merge request approval process from dev to staging , or staging to production. The problem is i need to only run this postman newman test when the process of merge request approval from staging to production, how can i achieve this?

like image 422
blue Avatar asked Dec 09 '25 09:12

blue


1 Answers

This can be achieved using the 'advanced' only/except settings in combination with supplied environment variables:

postman_tests:
    stage: postman_tests
    image: 
        name: postman/newman_alpine33
        entrypoint: [""] 
    only:
      refs:
        - merge_requests
      variables:
        - $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME == "staging"
        - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "production"
    script:
        - newman --version
        - newman run https://api.getpostman.com/collections/zzz?apikey=zzz  --environment https://api.getpostman.com/environments/xxx?apikey=xxxx

For a full list of predefined environment variables you can go here

like image 90
secustor Avatar answered Dec 11 '25 01:12

secustor