Subsequent stages should run even previous stage failed

If i define two jobs on one stage say

  • build:
       job1
       job2
    
  • deploy:
       job3
       job4
    

where job1 is dependent on job3 and job2 is dependent on job4. If job1 fails and job2 pass, job4 (job2 -> job4) should run automatically.

I think you want to use the allow_failure and dependencies tag in the gitlab-ci.yaml

where job1 and job2 have allow_failure: true and job3 and job4 depend on their corresponding build-jobs.

I created an example here

stages:
    - build
    - deploy

task1_build:
    stage: build
    script:
        - mv asdfasdf jfjewj
        - echo "hello job1" > job1.success 
    artifacts: # use artifacts to store "success message"
        untracked: true
        expire_in: 1 week
    allow_failure: true
        
        
task2_build:
    stage: build
    script: 
        # - add your actual tasks here
        - echo "hello job2" > job2.success
    artifacts: # use artifacts to store "success message"
        untracked: true 
        expire_in: 1 week
    allow_failure: true

        
task1_stage2:
    stage: deploy
    dependencies:
        - task1_build
    script:
        - cat job1.success # HACKY verification that stage1 was successful
        - echo "hello job3"
    allow_failure: true # you may want to allow failure here as well
        
        
task2_stage2:
    stage: deploy
    dependencies:
        - task2_build
    script: 
        - cat job2.success # HACKY verification that stage1 was successful
        - echo "hello job4"
    allow_failure: true # you may want to allow failure here as well