Issue when using Rules: -if

Hello!

We’ve been looking at ways of optimising our branching strategy and wanted to accomplish the following using the allow_failure option:

When a branch includes the name ‘feature’ or ‘spike’ then the step unit_tests is allowed to fail, otherwise unit_tests needs to pass for the pipeline to continue.

I came across the rules option and have been trying this method out as per the below screenshot:

Screenshot 2020-07-08 at 13.53.04

Tested the above code by creating a branch and naming it feature/xxxx and the allow_failure rule worked a treat, also tested by naming a branch test/xxxx which also worked as expected.

However, when trying to create a merge request I am getting the ‘detached’ tag showing and the merge pipeline fails only showing the unit_tests stage (when in reality we have 8 stages; npm_install etc - these are all templates)

Am I using rules in the correct way, or is there a better way of going about this? i.e. an alternative method

Any guidance greatly appreciated!

NOTE: We are using our own hosted version of Gitlab and are on version 12.9.2

Okay, so I’ve managed to get a bit further with this and have it so the Merge Request pipeline runs (although it does still say ‘detached’)

I’ve also noticed that when the Merge Request pipeline runs; the branch that I was working on and submitting to MR also runs its pipeline. Is there a way so that only the MR pipeline runs and not the branch?

Thanks!

2 Likes

i have also encountered strange behavior in regards to rules in gitlab ci and the official documentation is very weak.

See this link

1 Like

@jpip26 - was the issue that @tobyhersey shared helpful?

I am eager to hear if you were able to get this sorted out. :blush:

@Linds Yes, managed to sort it eventually but it was very painful having to find the answer via problems posts on forums rather than gitlab’s official documentation.

That does sound painful :frowning: @jpip26 - If there were things you found elsewhere that you wished were in our docs, please share them, or even better, start an MR!

We are always trying to improve our documentation, and real-life situations are the best to learn from! (ps. there is swag in it for you for you for helping us out!)