Replacing When with Rules for Needs

I need to, because of extending other tasks using rules and generally moving away from “when”, to change this snippet to use “rules”:

job:
    stage: build
    needs: [test-job]
    when: on success
        script:
            - [...]

It makes the job only start when the “test-job” job is successful. I have another manual job if it is unsuccessful.

How can i make a job dependent on the success or failure of another job using rules?

I have tested:

needs: [test-job]
rules:
    when: manual

but that is incorrect.

Maybe even using needs is wrong in this instance?

Rules are used when you want to control if that job is created based on a set of rules.

If you do not need any such rules - the job you want is to always be created - and only make the job depend on if previous jobs have run then how you had it is correct.

job:
    stage: build
    needs: [test-job]
    when: on success

Rules replaces only/except keywords.

1 Like